I have two entities:
Parent {
Child[] children;
}
and
Child {
Parent parent;
}
I'm aware about @JsonBackReference
and @JsonManagedReference
.
They are good, if I'm serializing instances of Parent
.
But I also need to transfer instances of Child
and I want to have the parent
field populated.
In other words:
- On serialization of
Parent
it should havechildren
but their parent field might be empty (can be solved by using json reference annotations). - On serialization of
Child
it should haveparent
with theirchildren
(butchildren
don't have to haveparent
populated.
Is there a way to solve it using standard Jackson capabilities?
I.e. skip serialization of entities which were already serialized instead of marking fields eligible or non-eligible for serialization.