jaxb-v2
jaxb-v2 copied to clipboard
JAXB Unmarshaller tries to instantiate abstract class ignoring xsi:type if it is a list element
JAXB ignores the xsi:type in SOAP request and tries to instantiate abstract class if the abstract element is in a list
2017-08-21 14:58:37.982 [http-nio-8080-exec-3] INFO com.sun.xml.bind.v2.ClassFactory - failed to create a new instance of class com.generali.ws.bipro.v2_6.datentypen.STEBauausfuehrung java.lang.InstantiationException: null at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101] at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_101] at com.sun.xml.bind.v2.ClassFactory.create0(ClassFactory.java:133) ~[jaxb-core-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.ClassFactory.create(ClassFactory.java:142) [jaxb-core-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:687) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl$TransducerImpl.parse(RuntimeClassInfoImpl.java:392) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.TextLoader.text(TextLoader.java:69) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:589) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.processText(StAXStreamConnector.java:338) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleEndElement(StAXStreamConnector.java:216) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:185) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:415) [jaxb-impl-2.2.11.jar:2.2.11] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:394) [jaxb-impl-2.2.11.jar:2.2.11]
SOAP Request: <sachen:Bauausfuehrung xsi:type="dt:STE_BauausfuehrungBasis">903</sachen:Bauausfuehrung>
Generated Java Code protected List<STEBauausfuehrung> bauausfuehrung;
xsd cutouts <xsd:element name="Bauausfuehrung" type="dt:STE_Bauausfuehrung" minOccurs="0" maxOccurs="unbounded"/>
<xsd:complexType name="STE_Bauausfuehrung" abstract="true"> xsd:simpleContent <xsd:extension base="xsd:string"/> </xsd:simpleContent> </xsd:complexType>
<xsd:complexType name="STE_BauausfuehrungBasis" final="#all"> xsd:simpleContent <xsd:restriction base="dt:STE_Bauausfuehrung"> <xsd:enumeration value="001"> xsd:annotation xsd:documentation001</xsd:documentation> </xsd:annotation> </xsd:enumeration> <xsd:enumeration value="002"> xsd:annotation xsd:documentation002</xsd:documentation> </xsd:annotation> </xsd:enumeration> </xsd:restriction> </xsd:simpleContent> </xsd:complexType>
the bug applies to both "marshal" and "unmarshal". On "marshal" the xsi:type information is lost.
i've created a reproducer project
pull request #1155 provides a fix for these issue.