Here is my problem:
I’m working on a project to migrate from Castor to JaxB. I am very new to JaxB and facing a problem which boggles my mind and yet, may be quite simple to solve. Here is a simple example :
class Data
{
private Item item;
}
I have Data containing one Item. Here is how the output XML file (which I cannot change) looks like:
<Data>
<Items>
<Item>
<Item>
<Items>
<Data>
Even though Data contains only one Item, it should be presented in the output XML as an element in Items. The thing is, I do not want JaxB to generate a class or property for Items, only Data and Item.
How should my schema look like? Is there any way to specify in the schema that the specified item is stored in a node which has no class representation? Something which in my logic could look like that:
<xs:element name="Data">
<xs:complexType>
<xs:sequence>
<xs:element ref="Items"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Items"> <!-- Do not generate plz -->
<xs:complexType>
<xs:sequence>
<xs:element ref="Item" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.
For the following fragment, there isn’t a way to generate the classes in that way, because the standard JAXB APIs don’t provide path based mapping.
However, starting from Java classes you could use MOXy’s
@XmlPathextension to map this use case:For More Information