Jackson @JsonManagedReference on collection(一对多)

时间:2016-02-27 23:07:11

标签: java json jackson one-to-many

我有以下两个班级。

School有很多TestTaker s

@Entity
@Table(name = "school")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class School extends BaseModel {

    @Column(name = "name")
    private String name;
    @OneToMany(mappedBy = "school")
    //    @JsonManagedReference <<<<< If not commented out, then error
    private Set<TestTaker> testTakers;
//getter setters
}

// TestTaker.java
@Entity
@Table(name = "test_taker")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class TestTaker extends BaseModel {
    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @ManyToOne
    @JoinColumn(name = "school_id")
    @JsonBackReference("school_testTaker")
    private School school;
//getters setters
}

有人可以解释为什么@JsonManagedReference不能在集合上注释吗?我会得到一个错误,说杰克逊无法处理托管/后退参考。 @JsonManagedReference在常见数据库关系中如何与@JsonBackReference一起使用一对一,一对多,多对一

我已经阅读了文档,但仍然不太了解杰克逊想要实现的目标

0 个答案:

没有答案