I have set up a test unit at github. Could someone please check why this is not working though the XML to unmarshal looks good?
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><message:GenericData xmlns:message=\"http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message\" xmlns:common=\"http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:generic=\"http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic\" xsi:schemaLocation=\"http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message https://sdw-wsrest.ecb.europa.eu/vocabulary/sdmx/2_1/SDMXMessage.xsd http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common https://sdw-wsrest.ecb.europa.eu/vocabulary/sdmx/2_1/SDMXCommon.xsd http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic https://sdw-wsrest.ecb.europa.eu/vocabulary/sdmx/2_1/SDMXDataGeneric.xsd\">\n"
+ "<message:Header>\n" ...
The most outer element GenericDataType gets instantiated correctly. I checked that using the debugger and setting a breakpoint into a hand-crafted public constructor. However, the message:Header element leads to instantiation of BaseHeaderType class which is abstract.
In SDMXMessage.xsd there is clearly stated that the GenericDataType's header is restricted to GenericDataHeaderType:
<xs:complexType name="GenericDataType">
<xs:annotation>
<xs:documentation>GenericDataType defines the contents of a generic data message.</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:restriction base="MessageType">
<xs:sequence>
<xs:element name="Header" type="GenericDataHeaderType"/>
<xs:element name="DataSet" type="data:DataSetType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="footer:Footer" minOccurs="0"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
Why does xjc ignore that during code generation?
public abstract class MessageType {
@XmlElement(name = "Header", required = true)
protected BaseHeaderType header;
@XmlAnyElement(lax = true)
protected List<Object> any;
@XmlElement(name = "Footer", namespace = "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message/footer")
protected FooterType footer;
public class GenericDataType
extends MessageType {
}
Is there anything I can do about that? Any automatic alternative for creating a Java domain model from XSD files that is actually working?
any
is typically a catch-all-property which appears when schema construct is too weird for XJC. In your case you might have naming collisions. Check yourMessageType
if there's aheader
or afooter
element etc. and try to customize that. – WellfavoredGenericDataType
and customize with<jaxb:class ref="...MyClass"/>
. – Wellfavored