Problem with deserialized JsonObject

32 views
Skip to first unread message

Dennis Benzinger

unread,
Jan 9, 2009, 11:50:45 AM1/9/09
to google-gson
Hi!

If I deserialize a JSON string into a JsonObject tree like it is
suggested in
http://groups.google.com/group/google-gson/browse_thread/thread/412b1dab8a67961e/b6fb1b672a348c34#42b46c904801adca
and then call toString on the object I get a null pointer exception if
the JSON object contains a null value.

Am I doing something wrong or is this a bug?

Code below:

import java.lang.reflect.Type;
import com.google.gson.*;

class GsonNPE {
public static void main(String[] args) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(JsonObject.class,
new JsonDeserializer<JsonObject>() {
public JsonObject deserialize(
JsonElement json, Type typeOfT,
JsonDeserializationContext context)
throws JsonParseException {
return json.getAsJsonObject();
}
})
.create();

JsonObject o = gson.fromJson("{\"name\": null}",
JsonObject.class);

o.toString();
}
}


Thanks for your help,
Dennis Benzinger
Reply all
Reply to author
Forward
0 new messages