Im trying to consume a large Json response. I keep receiving this error:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of java.util.ArrayList<com.justinswork.Corona.Tracking.Model.CountryDailyDataByProvince>
out of START_OBJECT token
Here's the json im trying to parse: (This is just one indices of the array).
{
"data":[
0:{
"date":"2020-04-16"
"confirmed":991
"deaths":6
"recovered":984
"confirmed_diff":0
"deaths_diff":0
"recovered_diff":0
"last_update":"2020-04-09 01:12:20"
"active":1
"active_diff":0
"fatality_rate":0.0061
"region":{6 items
"iso":"CHN"
"name":"China"
"province":"Anhui"
"lat":"31.8257"
"long":"117.2264"
"cities":[0 items
]
}
}
I'm trying to parse it using Jackson, but it keeps returning the out of START_OBJECT token error.
Here is my call to the external API, as you can see im using a List as a response type, which confuses me as to why im getting this error.
ResponseEntity<List<CountryDailyDataByProvince>> response = template.exchange(
"https://covid-19-statistics.p.rapidapi.com/reports?region_name={country}&date=2020-04-16",
HttpMethod.GET,
httpEntity, new ParameterizedTypeReference<List<CountryDailyDataByProvince>>() {
}, date, country);
List<CountryDailyDataByProvince> list = response.getBody();
And here is the class to which I'd like to parse the json to.
public class CountryDailyDataByProvince {
private int confirmed;
private int recovered;
private int deaths;
private int active;
private String province;
@JsonProperty( "region" )
private List<String> regions;
public CountryDailyDataByProvince(int confirmed, int recovered, int deaths, int active, String province,
List<String> regions) {
super();
this.confirmed = confirmed;
this.recovered = recovered;
this.deaths = deaths;
this.active = active;
this.province = province;
this.regions = regions;
}
I really can't figure out why Im getting this error. Any and all input would be greatly appreciated.
EDIT:
it was pointed out the JSON i posted wasn't raw JSON, here is raw JSON:
{
"data": [{
"date": "2020-04-16",
"confirmed": 991,
"deaths": 6,
"recovered": 984,
"confirmed_diff": 0,
"deaths_diff": 0,
"recovered_diff": 0,
"last_update": "2020-04-09 01:12:20",
"active": 1,
"active_diff": 0,
"fatality_rate": 0.0061,
"region": {
"iso": "CHN",
"name": "China",
"province": "Anhui",
"lat": "31.8257",
"long": "117.2264",
"cities": {
}
}
}
]
}