In my current android project, the API provides every JSON value in quotes:
{
"id":"1234",
"title":"Matrix",
"subTitle":"",
"year":"1999",
"rating":"9"
}
I can successfully map this to my model (Obviously Integers are recognized by GSON?).
int id;
String title;
String subtitle;
int year;
int rating;
The problem occurs, when a movie has no rating. In this case the API returns
"rating":""
GSON isn't able to map that to an int.
How can I convince GSON to replace ""
with -1
just for Integers, since I want to keep empty Strings e.g. for non-existent subtitles?
TypeAdapter
seems to be what I need, but wouldn't it replace every empty String (even the ones mapping to a String)?