fastjson一个集合被多次引用的问题

public class A {
    private B b;
    private C c;
    public B getB() {
        return b;
    }
    public void setB(B b) {
        this.b = b;
    }
    public C getC() {
        return c;
    }
    public void setC(C c) {
        this.c = c;
    }
    
}
View Code
public class B {
    private List<D> dlist;

    public List<D> getDlist() {
        return dlist;
    }

    public void setDlist(List<D> dlist) {
        this.dlist = dlist;
    }
    
}
View Code
public class C {
    private List<D> dlist;

    public List<D> getDlist() {
        return dlist;
    }

    public void setDlist(List<D> dlist) {
        this.dlist = dlist;
    }
    
}
View Code
public class D {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    
}
View Code
D d = new D();
        d.setName("张三");
        
        ArrayList<D> dList = new ArrayList<>();
        dList.add(d);
        
        B b = new B();
        b.setDlist(dList);
        
        C c = new C();
        c.setDlist(dList);
        
        A a = new A();
        a.setB(b);
        a.setC(c);
        
        String jsonString = JSON.toJSONString(a,SerializerFeature.DisableCircularReferenceDetect);
        System.out.println(jsonString);
View Code

 

posted @ 2020-06-05 14:23  顶风少年  阅读(113)  评论(0编辑  收藏  举报
返回顶部