转载自:
可以通过选项 DisableCircularReferenceDetect来禁止循环引用检测:
JSON.toJSONString( yourObject, SerializerFeature.DisableCircularReferenceDetect);
A a = new A();B b = new B(a);a.setB(b);String text = JSON.toJSONString(a); // {"b":{"a":{"$ref":".."}}}A a1 = JSON.parseObject(text, A.class);Assert.assertTrue(a1 == a1.getB().getA());
引用是通过"$ref"来表示的
引用 描述
"$ref":".." 上一级
"$ref":"@" 当前对象,也就是自引用
"$ref":"$" 根对象
"$ref":"$.children.0" 基于路径的引用,相当于 root.getChildren().get(0)
posted on 2015-09-14 16:48 阅读( ...) 评论( ...)