That doesn't really solve my issue because it doesnt scale really well, every time i add a relation to an entity i would need to find each reference to it and add the element to the JsonIgnoreProperties.
It would be a great addition (from my POV) if the JsonIdentityInfo allows the user to select the "scope" where the entity cant be serialized again. Anyway, thanks a lot for your reply. On Tuesday, April 9, 2019 at 3:29:37 PM UTC-4, Tatu Saloranta wrote: > > On Fri, Apr 5, 2019 at 11:38 AM <[email protected] > <javascript:>> 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 +- > -- Confidentiality Notice: This e-mail and any documents, files or previous e-mail messages attached to it may contain confidential information that is legally privileged. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of any of the information contained in or attached to this transmission is strictly prohibited. If you have received this transmission in error, please immediately notify the sender. Please destroy the original transmission and its attachments without reading or saving in any manner. -- 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.
