static class Foo{
private Map<String,String> mapData;
public Map<String, String> getMapData() {
return mapData;
}
public void setMapData(Map<String, String> mapData) {
this.mapData = mapData;
}
}
public static void main(String[] args) {
List<Foo> fooList = new ArrayList<>();
HashMap<String, String> mapData = new HashMap<>();
mapData.put("key1", "val1");
Foo foo = new Foo();
foo.setMapData(mapData);
Foo foo2 = new Foo();
foo2.setMapData(mapData);
fooList.add(foo);
fooList.add(foo2);
String fooListJson = JSON.toJSONString(fooList);
System.out.println(fooListJson);
List<Foo> fooListJsonParseRet = JSON.parseArray(fooListJson, Foo.class);
for (Foo fooItem : fooListJsonParseRet) {
System.out.println(JSON.toJSON(fooItem));
}
}
序列化结果:[{"mapData":{"key1":"val1"}},{"mapData":{"$ref":"$[0].mapData"}}]
反序列化结果:
{"mapData":{"key1":"val1"}}
{"mapData":{"$ref":"$[0].mapData"}}
暂无答案!
目前还没有任何答案,快来回答吧!