The following class needs to be marshalled to xml.
class A {
@XmlElement
private boolean readFlag;
// ... and some other fields
}
However, the readFlag
should only be in the returned xml, under some conditions. I can not use @XmlTransient
, because that would always leave it out.
Thanks in advance.
One thing you could do is use the
Boolean
wrapper class and set the value of the field tonull
if you don't want to have it marshalled -null
fields are left out by default.If you use EclipseLink/MOXy as JAXB implementation, you could also use its object graph feature, for a list of articles about that see here.