9

I'm using JSON to deserialize an input string that contains a null value for certain hashmap property. Does anyone have any clue why this exception occurs ? Is it possible that null is not accepted as a value Is this configurable somehow ?

input sample:

{"prop1":"val1", "prop2":123, "prop3":null}

stacktrace:

net.sf.json.JSONException: null object
    at net.sf.json.JSONObject.verifyIsNull(JSONObject.java:2856)
    at net.sf.json.JSONObject.isEmpty(JSONObject.java:2212)

Thanks.

1 Answer 1

7

For me this works with json-lib-2.3-jdk15:

String json = "{\"prop1\":\"val1\", \"prop2\":123, \"prop3\":null}";
JSONObject jsonObject = JSONObject.fromObject(json);
HashMap<String, Object> map = (HashMap<String, Object>) JSONObject.toBean(jsonObject, HashMap.class);

Actually the null value becomes an instance of JSONNull.

JSONNull is equivalent to the value that JavaScript calls null, whilst Java's null is equivalent to the value that JavaScript calls undefined.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.