Skip to content

JSONObject(Map) handling of null values has changed #296

Description

@effad

Before 2010-12 the JSONObject-constructor
public JSONObject(Map map)
accepted null values in the map and transformed them to JSONObject.NULL

i.e.:

    public static void main(String[] args) throws UnknownHostException {
        Map<String, Object> test = new HashMap<String, Object>();
        test.put("foo", null);
        System.out.println(new JSONObject(test));
    }

would give
{ foo: null }

Since then, there is a
if (value != null) {
line in the constructor which prevents that and thus the program above gives:
{}

This has broken the logic in our software quite fundamentally.

What is more, it also seems to be inconsistent with JSONObject.wrap, where null-values are expected:

            if (object == null) {
                return NULL;
            }

Is there any chance that the old (and IMO better) behaviour is restored?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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