I got an xsd and I generated JaxB-Classes from it (example ApplicationCustomType). Some classes have an xs:any as element. I can add content (example xs:any) to these fields. The marshalling works well.
But when I try to unmarshall it
FullContent contentType = XmlObjectHelper.getXmlTypeFromString(contentType, FullContent.class);
The JaxB-classes are not populated with the fields from every xs:any. All other fields filled in as they should but the binding of the xs:any seems not to work.
I read that serializing-with-jaxb answer and it looks pretty the same I don't think I forgot something. I also tried to add lax = true but again it did not unmarshal my xml.
What did I do wrong or what did I forget?
public class ApplicationCustomType {
@XmlAnyElement
protected List<Element> any;
@XmlAnyAttribute
private Map<QName, String> otherAttributes = new HashMap<QName, String>();
An example xs:any element.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addressAttachment", propOrder = {
"locale",
"ourUserId"
})
public class AddressAttachment {
@XmlElement(required = false)
protected String locale;
@XmlElement(required = false)
protected String ourUserId;
}
ObjectFactory.java
@XmlElementDecl(namespace = "http://***/xsd/addressAttachment/v1", name = "information")
public JAXBElement<AddressAttachment> createAddressAttachment(AddressAttachment value) {
return new JAXBElement<AddressAttachment>(_AddressAttachment_QNAME, AddressAttachment.class, null, value);
}
The xml I receive:
<content>
<applicationCustom>
<addressAttachment>
<locale>CH.de</locale>
<ourUserId>264646337383839</ourUserId>
</addressAttachment>
</applicationCustom>
</content>
Solution:
We retried it with (lax = true) on top of the List and not the class.
public class ApplicationCustomType {
@XmlAnyElement(lax = true)
protected List<Element> any;
If you use <Element>
or <Object>
does not affect the result. When using Element
you dont have to provide the class to the marshaller actually. But in both cases you need to add @XmlElementDecl
for each XMLRoot
class in your Object factory for each Object you want to add to the xs:any list.