例如,给定JSON:

[
{"id":"3", "location":"NewYork", "date":"yesterday"},
{"id":"4", "location":"Moscow", "date":"today"}
]


产生的HashMap:

<"3", POJOLocation("NewYork", "yesterday")>
<"4", POJOLocation("Moscow", "today")>


其中POJOLocation是Java对象:

class POJOLocation {
private String location;
private String date;
// etc
}


我曾尝试使用自定义反序列化器,但由于通用标记和hacking typeOfs确实使它肿了。也许有一个简单有效的解决方案?

最佳答案

也许创建一个POJOLocationId类:

class POJOLocationId {
private int id;
private String location;
private String date;
// etc
}


然后反序列化并循环遍历生成的List并随身携带HashMap吗?

09-25 22:30