How do you prevent JAXB from creating an intermediate object

sidene

New Member
I want to have the following XML\[code\]<doc> <items> <item /> <item /> <item /> </items> <things> <thing /> <thing /> <thing /> </things></doc>\[/code\]The schema would be something like\[code\]<schema> <element name="doc"> <complexType> <all> <element name="items" minOccurs="1"> <complexType> <sequence> <element name="item" minoccurs="0" maxoccurs="unbounded" /> </sequence> </complexType> </element> <element name="things" minOccurs="1"> <complexType> <sequence> <element name="thing" minoccurs="0" maxoccurs="unbounded" /> </sequence> </complexType> </element> </all> /<complexType> </element></schema>\[/code\]Now with JAXB it creates a class called Doc which would have an Items type which has an Item. Therefor to add the first element I have to do this.\[code\]Doc doc = new Doc();Items items = new Items();items.getItem().add(new Item());doc.setItems(items);\[/code\]I would like to be able to do the following instead:\[code\]Doc doc = new Doc();doc.getItems().add(new Item());\[/code\]Or even better:\[code\]Doc doc = new Doc();doc.addItem(new Item());\[/code\]Anyway of doing this through JAXB bindings?
 
Back
Top