I have a Model consisting in a main Manager
class, which has some variables, for example name
but also has a big object called data
. For a special case I want to pass from json to Model with Gson
but ignoring the data
Object of the json (for the normal case I will decode completely all the objects of the json).
I need to do this without anotations and without transient, just adding a deserializing rule to exclude Data
class in case I want to do it.
How can I specify ad decode time that I want to ignore a class?
My model:
public class Manager{
String name;
Data data;
}
public class Data{
String dummy;
String dummy2;
}
Json sample:
{"manager":{"name":"testname","data":{"dummy":"testname", "dummy2":"testname2"}}}
Code sample that decodes all:
GsonBuilder gsonBuilder = new GsonBuilder();
new GraphAdapterBuilder()
.addType(Data.class)
.addType(Manager.class)
.registerOn(gsonBuilder);
Gson gson = gsonBuilder.create();
Manager manager = gson.fromJson(json, Manager.class);