On Fri, Apr 5, 2019 at 11:38 AM <[email protected]> wrote:
>
> Hi!
>
> So, im tryin to use @JsonIdentityInfo to avoid ciclical relationships because
> i'm trying to serialize an hibernate entity with a one-to-many relationship.
>
> My functions needs to return a List of the child class element, and the
> serialization should include the parent but not the childs of the parent (to
> avoid the cycle), something like this:
>
> child: {prop1: xxxx, prop2: yyyy, parent: {propParent1: bbbbb, childs: null} }
>
> JsonIdentityInfo do this great, my problem happens when the same parent class
> has multiple childs in my list of elements, in this case the parent is only
> serialized in his first appearence and the next times the only thing shown is
> the id (as defined in JsonIdentityInfo).
>
> So, i want to know if its posible in to apply JsonIdentityInfo ONCE per
> element on the list, meaning: if two element of the list have the same parent
> serialize them both, but if the same element tries to serialize the same
> object two times, then serialize only the id
No, `@JsonIdentityInfo` is designed to serialize anything just once,
and after that always use id.
If you never wanted to include children of parents, you might be able
to prevent that by adding `@JsonIgnoreProperties` on parent reference
like:
public class Child {
@JsonIgnoreProperties({ "childs" })
Parent parent; // or List<Parent>
}
-+ Tatu +-
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.