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?

Thank you.

-- 
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.

Reply via email to