親/子参照を使用してオブジェクト グラフをシリアル化しようとしています。基本的に、次のようなエンティティがあります。
@Entity (name = "Container")
@JsonIdentityInfo(generator=JSOGGenerator.class)
public class Container {
public String type = "parent";
@JsonManagedReference ("child")
@OneToMany (mappedBy = "parent", cascade = CascadeType.PERSIST)
public List<Child> children;
}
@Entity (name = "Child")
@JsonIdentityInfo(generator=JSOGGenerator.class)
public class Child {
public String type = "child";
@JsonBackReference ("child")
@ManyToOne
public Parent parent;
}
これをクライアントにシリアル化しようとすると、次のようになります。
{
"type": "parent",
@id: 1
"children": [
{
"type": "child",
@id: 2
},
{ ... }
]
}
すべてのオブジェクトのプロパティが表示@id
されますが、プロパティがまったく表示されません@ref
。jsog と jsog-jackson を正しく理解していれば、実際にシリアル化する必要があるのは次のとおりです。
{
"type": "parent",
@id: 1
"children": [
{
"type": "child",
@id: 2
@ref: 1
},
{ ... }
]
}
私が本当にしたいのは、ブラウザーでシリアル化された JSOG を復元した後、元の後方参照を親に復元する方法です。これにより、各オブジェクトのプロパティ@ref
を取得する代わりに元に戻すことができます。parent
child