0
我想正確序列化對兩個對象以及它自己的對象可用的對象。我希望能夠看到網站管理員,以及用戶是管理員的網站以及特定網站的管理員。我曾嘗試使用@JSONbackmanaged,它只是提供了ID。是這樣的可能嗎?這是僞代碼,所以可能存在語法錯誤,但它儘可能接近。 Hibernate正在管理ORM並加載這些pojos。傑克遜與鏈接對象的雙向序列化
public class SiteAdmin {
private Integer id;
private Site site;
private User user;
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
public Facility getSite() {
return this.sitey;
}
public void setSite(Site site) {
this.site = site;
}
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
}
和user.java我有
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
public Set<SiteAdmin> getSiteAdmins() {
return this.siteAdmins;
}
和site.java我有
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
public Set<SiteAdmin> getSiteAdmins() {
return this.siteAdmins;
}
什麼我找的時候我序列是這樣的
適合用戶:
{
id: 2
name: 'foo',
siteAdmin: {
user: 2,
site: { id: 6, name: 'site' }
}
}
對於站點
{
id: 6
name: 'site',
siteAdmins: [
{
user: {id : 2, name: 'foo'},
site: 6
},
{
user: {id : 3, name: 'bar'},
site: 6
},
]
}
相反,我得到這樣的事情
{
id: 6
name: "site",
siteAdmins: [
{
site: {
id: 6
name: "site",
siteAdmins: [
site: 6,
user: {id : 2, name: "foo"}
]
},
user: {id : 3, name: "bar"}
},
1
]
}