I'm trying to get JAXB to ignore a wrapper class during the Mashalling process, it makes sense to have this wrapper class in code, as it keep all related information together, however I need to get rid of it during the marshaling process. The following is the relevant 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 the wrapper object that I'd like not have a node created for. I still want the Element, FieldType and ListType within the Resource to be rendered however.
This is what I currently 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>
What I'd like to achieve is 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 don't know if it's possible, but any help would be appreciated.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…