-
Notifications
You must be signed in to change notification settings - Fork 185
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
UnsupportedOperationException: Not a string: null #103
Comments
Here is an example of a use-case, from reading the contents of a REST response:
This throws an exception because the server always sends empty fields when there is no value (eg. no bio -> there is a 'bio' field but its value is 'null'). Since "no value" and "value is null" is essentially the same (especially for Strings, in which you can specify "" to say 'empty'), it would be nice that this simple code would work instead of throwing exceptions. |
And in the case where you actually want to know if the object contains the literal |
This would make working with this API a lot easier, please at least consider it. |
This fix works around the limitation of minimal-json, that null as default is not handled (see ralfstx/minimal-json#103 (comment))
This fix works around the limitation of minimal-json, that null as default is not handled (see ralfstx/minimal-json#103 (comment))
Here's a small example of the problem:
When running this, an
UnsupportedOperationException
is thrown. According to the doc ofgetString
, however:So I would expect that it would return the default value (since the value
null
is used to notify that there is no value).The only way currently to bypass the exception is to set the code to:
String content = json.get("test").isNull() ? "default" : json.getString("test", "default");
which is a lot for not much (and it's badly-optimized because there are two
get
calls).It would be nice if the methods would just return the default value if the content is null...
The text was updated successfully, but these errors were encountered: