我有两个实体:
Parent {
Child[] children;
}
and
Child {
Parent parent;
}
我知道@JsonBackReference和@JsonManagedReference。它们很好,如果我要序列化Parent.
但我还需要传输实例,Child并且我希望parent填充该字段。
换句话说:
- 在序列化时
Parent它应该有children,但它们的父字段可能是空的(可以通过使用 json 引用注释来解决)。 - 在它的序列化上
Child应该有parent他们的children(但children不必parent填充。
有没有办法使用标准的杰克逊功能来解决它?
即跳过已经序列化的实体的序列化,而不是标记符合或不符合序列化条件的字段。