Skip to content

UnsupportedOperationException: Not a string: null #103

@CLOVIS-AI

Description

@CLOVIS-AI

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions