Trying to deserialize an api repsonse like this:
{
"Afghanistan": {
"All": {
"confirmed": 157725,
"recovered": 0,
"deaths": 7332,
"country": "Afghanistan",
"population": 35530081,
"sq_km_area": 652090,
"life_expectancy": "45.9",
"elevation_in_meters": null,
"continent": "Asia",
"abbreviation": "AF",
"location": "Southern and Central Asia",
"iso": 4,
"capital_city": "Kabul",
"lat": "33.93911",
"long": "67.709953",
"updated": "2021-12-17 04:22:14"
}
},
"Albania": {
"All": {
"confirmed": 204928,
"recovered": 0,
"deaths": 3156,
"country": "Albania",
"population": 2930187,
"sq_km_area": 28748,
"life_expectancy": "71.6",
"elevation_in_meters": null,
"continent": "Europe",
"abbreviation": "AL",
"location": "Southern Europe",
"iso": 8,
"capital_city": "Tirana",
"lat": "41.1533",
"long": "20.1683",
"updated": "2021-12-17 04:22:14"
}
},
"Algeria": {
"All": {
...
}
}
}
and so on up to ~200 countries.
The problem is the format that implies me to trait each country as an individual object:
public class ApiResponse {
private Afghanistan afghanistan;
private Afghanistan albania;
private Afghanistan algeria;
private Afghanistan andorra;
private Afghanistan angola;
private Afghanistan antiguaAndBarbuda;
private Afghanistan argentina;
private Afghanistan armenia;
private Australia australia;
...
Hence I would like to have an array of countries, say:
{
"countries":[
{
"All": {
"confirmed": 157725,
"recovered": 0,
"deaths": 7332,
"country": "Afghanistan",
"population": 35530081,
"sq_km_area": 652090,
"life_expectancy": "45.9",
"elevation_in_meters": null,
"continent": "Asia",
"abbreviation": "AF",
"location": "Southern and Central Asia",
"iso": 4,
"capital_city": "Kabul",
"lat": "33.93911",
"long": "67.709953",
"updated": "2021-12-17 04:22:14"
},
{
"All": {
"confirmed": 204928,
"recovered": 0,
"deaths": 3156,
"country": "Albania",
"population": 2930187,
"sq_km_area": 28748,
"life_expectancy": "71.6",
"elevation_in_meters": null,
"continent": "Europe",
"abbreviation": "AL",
"location": "Southern Europe",
"iso": 8,
"capital_city": "Tirana",
"lat": "41.1533",
"long": "20.1683",
"updated": "2021-12-17 04:22:14"
}
]
}
I've already started digging into custom deserializers but couldn't figure out how to implement it yet. Appreciate any advice.