We have a Retrofit API using GSON as the converter, and it makes a call for a list of cards to display to the user. A card follows this format:
[
{
"cardType": "user",
"data": {}
},
{
"cardType": "content",
"data": {}
}
]
The data property varies between cards, so to resolve this we use GSON's RuntimeTypeAdapterFactory:
final RuntimeTypeAdapterFactory<Card> factory = RuntimeTypeAdapterFactory
.of(Card.class, "cardType")
.registerSubtype(UserCard.class, "user")
...
.registerSubtype(ContentCard.class, "content");
However, we've found that if the API is updated to include a new cardType that we aren't expecting, this silently fails to deserialize. By silently I mean, response.isSuccessful() still returns true, but the response.body() is null. The only way we were able to determine the new card type was the problem was through trial and error.
Is there any way to have GSON ignore any cardTypes that we haven't registered? If we try to add this new card but the app can't support it I would like to just ignore it.