GSON - Exclude Object based on Value of Field

Viewed 1168

I have some JSON, which contains a key named "type". This key can have the value include or exclude. I want to configure Gson to not deserialize the Json, and create an object when the key value is exclude.

I realize I can write a custom deserializer, check for the appropriate, and create the object or not. However, I was not sure if there was another way using some type of exclusion strategy.

The example I outlined is over-simplified. My real JSON contains many more fields.

// Deserialize me
{     
   "type" : "include"
}

// Skip over me, and do not deserialize
{
   "type" : "exclude"
}
2 Answers
Related