Is it possible to marshal a JAXB annotated class instance as its superclass (which is also a JAXB annotated class)?
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BenamningTYPE", propOrder = {"benamningId"})
@XmlSeeAlso({MoreDetailedBenamningTYPE.class})
public class BenamningTYPE {
...
@XmlElement(name = "BenamningId", required = true)
protected IdentifierTYPE benamningId;
...
}
And the extended type:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MoreDetailedBenamningTYPE", propOrder = {"modifyDetails"})
public class MoreDetailedBenamningTYPE extends BenamningTYPE {
...
@XmlElement(name = "ModifyDetails", required = true)
protected ModifyDetailsTYPE modifyDetails;
...
}
So if this scenario:
BenamningTYPE b = new MoreDetailedBenamningTYPE();
...
Then I would like to marshal the instance b as BenmaningTYPE to get
<BenmaningTYPE>
...
</BenmaningTYPE>
And NOT:
<MoreDetailedBenamningTYPE>
...
</MoreDetailedBenamningTYPE>
How would this marshal invoke look like, if possible?
I haven’t checked it, but I’d try first:
If you’re generating classes from an XML Schema, check also the copyable plugin. You could the copy data from an instance of
MoreDetailedBenamningTYPEto the instanceBenmaningTYPEand marshal that.There are more possibilities, but they’re a bit more complex.