I'm using JAXB 2.1 to go from my domain model to XML (and vice-versa).
Let's say my model is the following, where Install and Remove are subclasses
of AbstractAction:
AbstractAction
^
|
|--Install
|--Remove
In the schema that I have to support, the concrete AbstractAction subclasses
are 'wrapped' in an Action element:
<Action>
<Install refreshInterval="..."/>
</Action>
The domain model has no need for aggregation of an AbstractAction within
some 'Action' class - and I don't want to pollute it with unnecessary
classes just to make it serialize correctly.
What's the correct approach to insert this 'wrapper' Action element which
will contain a real AbstractAction element for Install or Remove when
marshalling to XML?
Unmarshalling?
Is this a job for an XmlAdapter?
Schema example - Note that I can't change the schema.
<xs:element name="Action">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element ref="Install"/>
<xs:element ref="Remove"/>
</xs:choice>
<xs:choice>
<xs:element name="InstallTime" >
<xs:complexType>
<xs:attribute name="expire" use="optional" type="xs:time"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
TIA,
Rowland
--
View this message in context: http://www.nabble.com/marshall-wrapper-element-that%27s-not-present-in-model-tf4179731.html#a11885665
Sent from the java.net - jaxb users mailing list archive at Nabble.com.