Java - JSON Null Exception
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 callsnull
, whilst Java'snull
is equivalent to the value that JavaScript callsundefined
.