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

Feature to allow null-valued properties in output from parseJSON(Reader i) #2051

Merged
merged 1 commit into from Mar 2, 2017

Conversation

Projects
None yet
2 participants
@twilkinson
Copy link
Contributor

commented Mar 2, 2017

This change applies to the parseJSON(Reader i) method for the JSONParser class. As currently implemented, the Map returned by that method does not include properties from the incoming JSON stream whose values are null. They just do not exist in the output Map.

This request implements two new methods:

public static boolean isIncludeNulls() {}
public static void setIncludeNulls(boolean aIncludeNullsDefault) {}

If set to true, properties whose values are null will be included in the Map returned by parseJSON(Reader i).

EDITED:
So, for example, this change would allow a program to distinguish between cases 2 and 3:

case 1: { "a": 2, "x": 1 } means xexists with value 1
case 2: { "a": 2, "x": null } means x exists, but with value null (unknown)
case 3: { "a": 2 } means x does not exist.

(also, see the comment below by codenameone.)

@codenameone codenameone merged commit b9ed39a into codenameone:master Mar 2, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@codenameone

This comment has been minimized.

Copy link
Owner

commented Mar 2, 2017

Thanks, took me a moment to understand the use case so for other people reading it. This means that if the JSON has x=null within it the default behavior when I do resultMap.keySet() will not include x at all. This behavior will include it.

@twilkinson

This comment has been minimized.

Copy link
Contributor Author

commented Mar 2, 2017

Yes, that's correct. I've edited my original comment to include an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.