0
代码如下:
class XX {
int a;
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
}
Map<String, Object> result = new HashMap<>();
XX a = new XX();
a.a = 100;
List< XX> t = Arrays.asList(a);
Map<String, Object> y = new HashMap<>();
y.put("2_wdk", t);
Map<String, Object> x = new HashMap<>();
x.put("y", y);
result.put("a.b.c", x);
result.put("x", a);
String s = JSON.toJSONString(result);
System.out.println(s); // {"a.b.c":{"y":{"2\\_wdk":[{"a":100}]}},"x":{"$ref":"$.a\\.b\\.c.y.2\\\\\\_wdk[0]"}}
JSONObject revert = JSON.parseObject(s);
System.out.println(JSON.toJSONString(revert)); // {"a.b.c":{"y":{"2\\_wdk":[{"a":100}]}},"x":[]}
对于key=2_wdk这种数字开头,$ref="$.a\.b\.c.y.2\\\_wdk[0]",反序列化会丢失