I have this class:
Class B {
private String D;
private String E;
}
Using XStream, I would like to generate XML like this, where elements A and B are generated in the XML, even though they don’t exist in the java.:
<A>
<B>
<C>
<D/>
<E/>
</C>
</B>
</A>
Possible?
Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
Since you are looking for an annotation based solution, you may be interested in the
@XmlPathextension in MOXy.B
The
@XmlPathannotation allows you to specify your mapping as an XPath.jaxb.properties
To specify MOXy as your JAXB provider you need to include a file called
jaxb.propertiesin the same package as your domain model with the following entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html).Demo
input.xml/Output
For More Information