我一直在尝试反序列化从此API收到的数据:
{
"result": "success",
"timestamp": 1521038012878,
"data": {
"GB": 14,
"DE": 2,
"US": 2
},
"totalIsPublic": true,
"advanced": false,
"totalDownloads": {
"GB": 14,
"DE": 2,
"US": 2
}
}
这是 POJO 类:
public class BintrayDownloadCounts {
private List<Integer> totalDownloads = new ArrayList<>();
@JsonProperty("totalDownloads")
public List<Integer> getTotalDownloads() {
return totalDownloads;
}
public void setTotalDownloads(List<Integer> totalDownloads) {
this.totalDownloads = totalDownloads;
}
}
当我尝试使用反序列化时:
downloadCounts = mapper.readValue(json, BintrayDownloadCounts.class);
我收到此错误:
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token
我已经看到许多包含此错误的问题,但我无法为这个特定用例找出解决方案。可以注意到,totalDownloads
对象是动态的,即其内容不是恒定的。