I\'ve got such xml construction which I need to convert into java objects using JAXB:
You will need to define a custom XmlAdapter. The complicated part in your case is that you want to map one XML element
into multiple Java Element
objects. This means that, in Java., your XmlAdapter
needs to be configured for collection of Element
objects. Assuming your example XML fragment is part of a document:
....
Then you will need to configure the XmlAdapter
for the List
field in the Java Document
class:
class Document {
@XmlJavaTypeAdapter(CustomAdapter.class)
List elements;
}
Then you your CustomAdapter
class can receive a list of Element objects (corresponding to the actual XML structure with the nested items) and produce a list of Element with the structure you want.
For an example, check JAXB XmlAdapter – Customized Marshaling and Unmarshaling