How to conditionally output XmlElement in JAXB



We have a class Foo that has a collection of Bars, which in turn hold a reference to Foo. Sometimes we want JAXB to output a Foo with all underlying Bars, sometimes we want to output a Bar with its Foo embedded. We currently use a cycle detection mechanism for JAXB to return a dummy value and avoid endless loops. Sometimes this mechanism doesn't work, and we were unable to pinpoint this so far. Is there a way to make the @XmlElement conditional, ie to set in advance whether you want the containing Foo to be output or not? Another option would be to just set Foo to null there :-)


No comments:

Post a Comment