有没有办法用@JsonIdentityInfo影响序列化过程,以便它插入整个对象而不是引用id?
@Entity @JsonIdentityInfo( generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "linkLabel") public class LinkLabel implements Serializable { //... }
因此,杰克逊应该包含整个对象,而不是引用id为1的"otherObj".
{ "objects": [{ "id": 1, "otherObj": [{ "id": 1, ... }, { "id": 3, ... }] }, "id": 2, "otherObj": [1] <-- referencing otherObj with id 1 ] }
像这儿:
{ "objects": [{ "id": 1, "otherObj": [{ "id": 1, ... }, { "id": 3, ... }] }, "id": 2, "otherObj": [{ "id": 1, <-- desired format, whole object ... }] ] }
我们有双向引用,因此@JsonManagedReference和@JsonBackReference无法正常工作.此处描述了此行为(http://wiki.fasterxml.com/JacksonFeatureObjectIdentity).