Roo*_*oky 5 java json jackson jsonidentityinfo
有没有办法用@JsonIdentityInfo影响序列化过程,以便它插入整个对象而不是引用id?
@Entity
@JsonIdentityInfo(
generator = ObjectIdGenerators.IntSequenceGenerator.class,
property = "linkLabel")
public class LinkLabel implements Serializable {
//...
}
Run Code Online (Sandbox Code Playgroud)
因此,杰克逊应该包含整个对象,而不是引用id为1的"otherObj".
{
"objects": [{
"id": 1,
"otherObj": [{
"id": 1,
...
}, {
"id": 3,
...
}]
},
"id": 2,
"otherObj": [1] <-- referencing otherObj with id 1
]
}
Run Code Online (Sandbox Code Playgroud)
像这儿:
{
"objects": [{
"id": 1,
"otherObj": [{
"id": 1,
...
}, {
"id": 3,
...
}]
},
"id": 2,
"otherObj": [{
"id": 1, <-- desired format, whole object
...
}]
]
}
Run Code Online (Sandbox Code Playgroud)
我们有双向引用,因此@JsonManagedReference和@JsonBackReference无法正常工作.此处描述了此行为(http://wiki.fasterxml.com/JacksonFeatureObjectIdentity).
正如评论和链接中所述,@JsonIdentityInfo 和 Jackson Generators 似乎没有选项可以插入对象而不是 id。
经过更多研究,我们终于发现了这一点: 在包含 JsonIdentityInfo 的 JavaScript 中反序列化 Jackson 对象
这正是我们所遇到的场景,我们现在使用 JSOG,它针对双向引用进行了优化,并且它在服务器和客户端 (AngularJS) 端的工作方式就像一个魅力。
| 归档时间: |
|
| 查看次数: |
6371 次 |
| 最近记录: |