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
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();
Just declare it as of type JsonObject
class ExampleJsonModel {
@SerializedName("type")
public String type;
@SerializedName("object")
public JsonObject object;
}