0
我有2個雙向模型,我使用JsonIdentityInfo
預防json結果中的無限遞歸。這是我的ViewModels:是否有任何JavaScript庫來表示@JsonIdentityInfo的json結果?
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class GroupsViewModel extends BaseEntityViewModel<Long> {
private String title;
private Set<UserViewModel> users;
}
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class UserViewModel extends BaseEntityViewModel<Long> {
private String username;
private String password;
private Set<GroupsViewModel> groups;
}
和我的JSON結果的一部分是象下面這樣:
[{
"id" : 1,
"title" : "adminGroup",
"users" : [{
"id" : 1,
"username" : "admin",
"password" : "...",
"groups" : [1]
}, {
"id" : 31,
"username" : "user78",
"password" : "...",
"groups" : [1]
}, {
"id" : 3,
"username" : "ali",
"password" : "...",
"groups" : [{
"id" : 2,
"title" : "newsWriterGroup",
"users" : [{
"id" : 14,
"username" : "staff1",
"password" : "...",
"groups" : [{
"id" : 1005,
"title" : "FileManagerAccessGroup",
"users" : [{
"id" : 25,
"username" : "test1",
"password" : "...",
"groups" : [1005, {
"id" : 1006,
"title" : "noAccessGroup",
"users" : [25, {
"id" : 26,
"username" : "test5",
"password" : "...",
"groups" : [1006]
}
]
}
]
}, 14]
}, 2]
}, ...
如上文所示,如果對象是在JSON結果重複的,傑克遜只把它是它標識。現在我想知道是否有任何JavaScript/jQuery庫來表示@JsonIdentityInfo的json結果?例如,當使用Javascript/jQuery庫在1005標識到達,它自動加載組對象使用id = 1005
JSON可以被解析以使用'JSON.parse'本地JavaScript數組和對象。沒有必要導入一個庫。 – 4castle