Take the 2-minute tour ×

I am trying to deserialize a json object into a java bean. The main issue I am facing is that I'd like to treat the field object of the json string as a plain string, even if it contains a potentially correct json object. The json structure is like this:


How can i tell gson to ignore the object value so that it doesn't get deserialized into an object? I'd like it only to be mapped to a plain String field in my bean so that I can dispose a proper deserialization for it, once I got the type from the type field.

share|improve this question
i managed to partially deserialize the object watching this answer: stackoverflow.com/questions/3769473/… –  mox601 Mar 21 '11 at 14:15
add comment

2 Answers

I don't know if your problem is solved. I ran into a similar question and here it is how I worked it out:

JsonDeserializer allows you to make you own adapter to deserialize that **:

class JavaBeanDeserializer implements JsonDeserializer<JavaBeanObject>() {
    public JavaBeanObject fromJson(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    // return JavaBeanObject built using your logic.

You've to register JavaBeanDeserializer to Gson object when building it:

Gson gson = new GsonBuilder().registerTypeAdapter(JavaBeanObject.class, new JavaBeanDeserializer()).create();
share|improve this answer
didn't try your solution, but solved this with the link in the previous comment –  mox601 Apr 13 '11 at 7:19
add comment

Just declare it as of type JsonObject

class ExampleJsonModel {
    public String type;

    public JsonObject object;
share|improve this answer
add comment

Your Answer


