I am trying to get JAXB to ignore the wrapper class during the Mashalling process, it makes sense to have this wrapper class in the code, since it stores all the related information together, however I need to get rid of it during the marshaling process. Below is the corresponding code.
@XmlType(name = "root") @XmlRootElement(name = "root") public class Root { @XmlElementRef private List<Resource> resources = new ArrayList<>(); public void addResource(Resource resource) { resources.add(resource); } } @XmlRootElement(name = "", namespace = "") @XmlAccessorType(XmlAccessType.NONE) public class Resource { @XmlElementRef private Element element; @XmlElementRef private FieldType fieldType; @XmlElementRef private ListType listType; }
Root is the main object, and Resource is a wrapper object for which I would not create a node. However, I still want Element, FieldType, and ListType to appear in the Resource.
This is what I have:
<root> <> <element name="resource1"/> <fieldType name="resource1--type"> </fieldType> <listType name="resource--list"> </listType> </> <> <element name="resource2"/> <fieldType name="resource2--type"> </fieldType> <listType name="resource2--list"> </listType> </> </root>
I would like to get the following:
<root> <element name="resource1"/> <fieldType name="resource1--type"> </fieldType> <listType name="resource--list"> </listType> <element name="resource2"/> <fieldType name="resource2--type"> </fieldType> <listType name="resource2--list"> </listType> </root>
I do not know if this is possible, but any help would be appreciated.
Thanks.
source share