-
Notifications
You must be signed in to change notification settings - Fork 188
Open
Description
Here's a small example of the problem:
JsonObject json = new JsonObject();
json.add("test", (String) null);
String content = json.getString("test", "default");
When running this, an UnsupportedOperationException is thrown. According to the doc of getString, however:
If this object does not contain a member with this name, the given default value is returned.
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...
Metadata
Metadata
Assignees
Labels
No labels