小编bbk*_*glb的帖子

无法获取@JsonIdentityInfo注释

我有两个对象之间的双向关系.我有一个使用Jersey 1.17和Jackson 2.1.4的RESTful Web服务.我也在使用@JsonIdentityInfo注释(显然是错误的方式!)来阻止Json进入无限循环.但是,生成的Json仍然是两个对象之间的无限循环.

第一个对象是:

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class Child {

    private long value;
    private Parent parent;

    public long getValue() {
        return this.value;
    }

    public void setValue(long value) {
        this.value = value;
    }

    public Parent getParent() {
        return this.parent;
    }

    public void setParent(Parent parent) {
        this.parent = parent;
    }

}
Run Code Online (Sandbox Code Playgroud)

第二个对象是:

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class Parent {

    private long value;
    private Set<Child> childs = new HashSet<Child>(0);

    public long getValue() {
        return this.value; …
Run Code Online (Sandbox Code Playgroud)

rest json java-ee jackson

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

jackson ×1

java-ee ×1

json ×1

rest ×1