解决循环引用
Solving circular reference
我有两个classes
class A 有
private B messageOwner;
class B 有
@JsonIgnore
private List<A> messages = new ArrayList<>();
现在,当我想将 class A 作为 json 发送时,我希望它还包含有关 class B(没有列表)
的信息
然而使用这个它完全省略了 class B。我尝试使用@JsonManagedReference、@JsonBackReference 但结果是一样的。
解决这个循环引用的正确方法是什么?
@Transient
private B messageOwner;
这对 JSON 序列化的作用与 transient
类型修饰符对正常序列化的作用相同。如果 JSON 库支持它。
当然 messageOwner
在反序列化后将为 null。
我有两个classes
class A 有
private B messageOwner;
class B 有
@JsonIgnore
private List<A> messages = new ArrayList<>();
现在,当我想将 class A 作为 json 发送时,我希望它还包含有关 class B(没有列表)
的信息然而使用这个它完全省略了 class B。我尝试使用@JsonManagedReference、@JsonBackReference 但结果是一样的。
解决这个循环引用的正确方法是什么?
@Transient
private B messageOwner;
这对 JSON 序列化的作用与 transient
类型修饰符对正常序列化的作用相同。如果 JSON 库支持它。
当然 messageOwner
在反序列化后将为 null。