Is there any annotation on Gson for fields that I would like to be included/excluded from serialization if they have null
value?
class Person {
String lastname;
String firstname;
String address
}
I would like the fields lastname and firstname to be always included on serialization independent on its values (null or not) and the field address to be included only when it is not null
.
serializeNulls()
doen't work for me because it includes all the fields.
new GsonBuilder().serializeNulls().create()