FastJSON循环引用问题
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.htmlparser.util.ParserException;
/**
* Created by Vincent on 2014/12/18.
*/
public class Demo {
public static void main(String[] args) throws ParserException {
Demo1 demo1 = new Demo1();
Demo2 demo2 = new Demo2();
demo1.setDemo2(demo2);
demo1.setId(1);
demo2.setId(1);
demo2.setDemo1(demo1);
System.out.println(JSON.toJSONString(demo2, SerializerFeature.DisableCircularReferenceDetect));
}
}
class Demo1{
private int id;
private Demo2 demo2;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Demo2 getDemo2() {
return demo2;
}
public void setDemo2(Demo2 demo2) {
this.demo2 = demo2;
}
}
class Demo2{
private int id;
private Demo1 demo1;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Demo1 getDemo1() {
return demo1;
}
public void setDemo1(Demo1 demo1) {
this.demo1 = demo1;
}
}在这个例子中,有循环引用的问题,按照网上查找的资料使用的,出现了
java.lang.StackOverflowError异常,各位大师帮忙看看怎么破啊
...全文
相关推荐
详解在springmvc中解决FastJson循环引用的问题
本篇文章主要介绍了在springmvc中解决FastJson循环引用的问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
解决FastJson中"$ref重复引用"的问题方法
主要介绍了解决FastJson中"$ref重复引用"的问题方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
fastJSON.pdf
。。。
springMVC利用FastJson接口返回json数据相关配置详解
本篇文章主要介绍了springMVC利用FastJson接口返回json数据相关配置详解,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
SpringBoot整合FastJson过程解析
主要介绍了SpringBoot整合FastJson过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下


