Karthik
Karthik

Reputation: 470

JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

The below is my JSON response,

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.PushbackInputStream@bce1d9; line: 1, column: 556] (through reference chain: com.totalHours["data"]->com.totalHours["hourly_totals"])

 "totalHours": 
  {
     "hourly_totals": 
     {
        "2013112101":
        {
           "distance": 1324,
           "calories": 90.0120018125,
           "steps": 1603,
           "active_time": 793,
           "inactive_time": 220,
           "longest_active_time": 302,
           "longest_idle_time": 780
        },
        "2013112101":
        {
           "distance": 626,
           "calories": 47.0120018125,
           "steps": 455,
           "active_time": 246,
           "inactive_time": 260,
           "longest_active_time": 203,
           "longest_idle_time": 650
        },
        ... more hours ...
     }  

I have took a pojo class like below, I am getting an exception when I try to deserialize the my json data.

public class totalHours{
private List<String> hourly_totals;
}

But, I don't know whether to take a List because there is no array in response. What will be the other options to try out for.

Upvotes: 3

Views: 4110

Answers (1)

JP Moresmau
JP Moresmau

Reputation: 7393

hourly_totals is an object from an hour represented as a string to another object, to Map<String,T> , where T is a POJO class representing the data for one hour, would look like a natural choice.

Upvotes: 2

Related Questions