Jackson @JsonManagedReference for collection (one for many)

I have the following two classes.

Schoolhas a lot TestTakers

@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
}

Can someone explain why @JsonManagedReference cannot be annotated in a collection? I would get an error saying that Jackson cannot handle the managed / backlink. How exactly does @JsonManagedReference work with @JsonBackReference in shared database relationships? One-to-one, one-to-many, many-to-one

I read the documentation, still do not quite understand what Jackson is trying to achieve

+4
source share

All Articles