On Monday, February 18, 2019 at 4:35:41 PM UTC-5, Tatu Saloranta wrote: > > > > On Mon, Feb 18, 2019 at 1:27 PM Lalit Patil <[email protected] > <javascript:>> wrote: > >> I need to serialize a Java object with ID sometimes, and without Id at >> other times, >> >> For example, consider the following: >> >> public class Parent{ >> int id; >> private Child childObjectl >> } >> >> public class Child{ >> int id; >> String countryOfChild; >> } >> >> If I use @JsonIdentityReference(alwaysAsId=true) for *childObject *above, >> I would always get the id. If I don't use, the object would be serialized >> with the full details. >> >> However, I want the to do the following >> serialize the childObject with an id always, except if the countryOfChild >> is "USA". >> >> Thus, if my Child is >> { >> id = 1; >> countryOfChild = "CAN"; >> } >> >> I should get the serialized object with just the id reference. >> >> However, if the object is {id = 1; countryOfChild = "USA"}, then I want >> the serialized object with the full details. >> >> How do I achieve the above? >> > > I don't think there is a way to do that by default functionality. > > -+ Tatu +- > > >> >> Thank you, I wonder if anyone has a workaround idea to get it to work...
-- 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.
