Reputation: 462
Is there a way to dynamically exclude certain attributes of a class during gson serialization? (Based on a parameter I pass to the writer)
Or should I make 2 different serializers?
Thanks!
Upvotes: 0
Views: 677
Reputation: 5158
Try using transient
attribute. Ex:
private transient String name;
Also you can add this property
Gson gson = gsonBuilder.excludeFieldsWithModifiers(Modifier.TRANSIENT).create();
Edit: Take a look here
Upvotes: 4