以下に示すように、双方向の多対多の関係で2つのクラスがあります。
Parent implements Serializable{
@ManytoMany(//declaration for join table)
@JsonBackReference
@com.fasterxml.jackson.annotation.JsonIgnore
Set <Child> childSet;
}
Child implements Serializable{
@ManytoMany(//declaration for join table)
@JsonManagedReference
@com.fasterxml.jackson.annotation.JsonIgnore
Set <Parent> parentSet;
// other getter and setters
}
特定の親を取得するために、DAO で呼び出しを行います。親の詳細とともに、親の子を取得したいと思います。このようなもの:
Hibernate.initialize(parent.getChildSet()); //this works perfectly
// and I get the details of parent along with the children in my DAO call.
しかし、データをコントローラーに返すときにビジネス サービスで以下を実行すると、子は親の json 文字列から省略されます。
jacksonMapper.writeValueAsString(parent);
そのため、Parent クラス内の @JsonIgnore on Child 属性を削除しました。以下に示すように、文字列への書き込み中にこれらのフィールドを無視しないことをジャクソンが理解できると考えています。しかし、それはまだそれらを無視します! :(
Parent implements Serializable{
@ManytoMany(//declaration for join table)
@JsonBackReference
//@com.fasterxml.jackson.annotation.JsonIgnore
Set <Child> childSet;
}
私が間違っている可能性がある場所はありますか?