Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

java - Why am i getting the out of START_OBJECT token error?

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": {

                }
            }
        }

    ]
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...