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

≡放荡痞女 提交于 2019-12-23 20:58:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/31209868/json-deserialization-throwing-exception-can-not-deserialize-instance-of-java-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!