Hello,
I am processing XML documents with JAXB 2.0 where I need information(in my example 'id') mapped to Java objects and run some business logic with. Everything works fine here.
But these XML documents always hold a collection of approximately 500 nodes that I just want to save to a database in the original xml format, so I am just interested in the XML in form of a String. In my opinion it makes no sense to unmarshal these nodes to Java objects and later on marshal them again into XML to save them into the database.
Is there any way to annotate a property and make it just hold the whole XML node as a String? Here is my current version of that class:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Parent {
@XmlElement(name = "id")
public long id;
@XmlElement(name = "child", type = String.class)
@XmlElementWrapper(name = "children")
public List<String> children = new ArrayList<String>();
}
After unmarshalling an XML document children.size() returns the correct number of childran but they are still null.
The XML document looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<parent>
<id>45</id>
<children>
<child>
<name>Crash Dummy</name>
<age>21</age>
</child>
<child>
<name>Rockstar Programmer</name>
<age>12</age>
</child>
</children>
</parent>
Thanks in advance for every hint or a possible solution.