I'm working to deserialize World Weather Online API results with localizations.
the localization data returned as a lang-{locale}
block depending by the given language (WWO supports ~40 languages:
"hourly": [
{
"chanceoffog": "0",
"chanceoffrost": "0",
"chanceofhightemp": "0",
"chanceofovercast": "63",
"chanceofrain": "3",
"chanceofremdry": "0",
"chanceofsnow": "0",
"chanceofsunshine": "0",
"chanceofthunder": "0",
"chanceofwindy": "0",
"cloudcover": "88",
"DewPointC": "1",
"DewPointF": "34",
"FeelsLikeC": "4",
"FeelsLikeF": "39",
"HeatIndexC": "7",
"HeatIndexF": "44",
"humidity": "67",
"lang_ru": [
{
"value": "Пасмурно"
}
],
"precipMM": "0.0",
"pressure": "1033",
"tempC": "7",
"tempF": "44",
"time": "24",
"visibility": "10",
"weatherCode": "122",
"weatherDesc": [
{
"value": "Overcast"
}
],
"weatherIconUrl": [
{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0004_black_low_cloud.png"
}
],
"WindChillC": "4",
"WindChillF": "39",
"winddir16Point": "WNW",
"winddirDegree": "294",
"WindGustKmph": "17",
"WindGustMiles": "11",
"windspeedKmph": "14",
"windspeedMiles": "9"
}
]
It also can be lang_es
, lang_fr
etc..
I need to deserialize it to one field with the string inside regardless of the language given.
One ugly solution I thought about is adding 40 fields according to the languages and checking if the relevant is not null.
The other quite ugly solution is writing a full custom deserializer for hourly, but hourly has loads of (over 30) simple string fields so writing a custom deserializer for it seems inefficient and against the simplicity of GSON.
Is there any better neat and simple solution to write a custom deserializer only for the lang objects and allow GSON to automatically deserialize the rest of the data?