Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON output type returns all values as a string #18

Closed
mooreds opened this issue Sep 26, 2012 · 2 comments
Closed

JSON output type returns all values as a string #18

mooreds opened this issue Sep 26, 2012 · 2 comments
Labels

Comments

@mooreds
Copy link
Contributor

mooreds commented Sep 26, 2012

The JSON output type (_output=application/json) returns everything as a string.

That makes sense for the XML output type, when everything is an attribute. But JSON supports number and boolean as well as string, so if a column is either of those, it should be output in that form.

@restsql
Copy link
Owner

restsql commented Sep 26, 2012

Right you are Sir. We could definitely drop the double quotes from boolean and numeric data types. That would avoid requiring consumers having to cast.

@mooreds
Copy link
Contributor Author

mooreds commented Sep 27, 2012

Right. One issue I can see is that it wouldn't be backward compatible, but since JSON was only added recently, I'm not sure how big a problem that is. I guess you could document it, or add some kind of switch to default it back.

The relevant section of code looks to be in restsql/src/org/restsql/core/impl/JsonResponseSerializer.java in appendNameValuePair. Changing

string.append(JsonUtil.quote(value.toString()));

to

if (value instanceof Number) {
string.append(value);
} else {
string.append(JsonUtil.quote(value.toString()));
}

Not quite sure how to handle booleans, though.

@restsql restsql closed this as completed in f3aa586 Oct 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants