Is there an option (except writing custom serializer/deserializer) in GSON library to NOT serialize/deserialize beyond some level of extended classes.
For example see the following usecase
class FirstClass {
int firstVariable;
}
class SecondClass extends FirstClass {
int secondVariable;
}
class ThirdClass extends SecondClass {
int thirdVariable;
}
And now when using fromJson and toJson I would like to only serialize/deserialize first two classes in hierarchy – ThirdClass and SecondClass. Which means it would ignore whole FirstClass (and firstVariable in it) because that’s already at level 3.
You cannot generically exclude the TopLevel Class, what you could do is use an
ExclusionStrategy:You can also add a ExclusionStrategy to Deserialization.