Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAXB Unmarshaller tries to instantiate abstract class ignoring xsi:type if it is a list element #1135

Closed
Tomas-Kraus opened this issue Aug 21, 2017 · 7 comments
Milestone

Comments

@Tomas-Kraus
Copy link
Member

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 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>

@Tomas-Kraus
Copy link
Member Author

@NiasSt90 Commented
the bug applies to both "marshal" and "unmarshal".
On "marshal" the xsi:type information is lost.

i've created a reproducer project

@Tomas-Kraus
Copy link
Member Author

@NiasSt90 Commented
pull request #1155 provides a fix for these issue.

@Tomas-Kraus
Copy link
Member Author

vrlgohel pushed a commit to vrlgohel/jaxb-ri that referenced this issue Dec 27, 2018
gaol added a commit to gaol/jaxb-ri that referenced this issue Feb 18, 2019
Original PR from: javaee/jaxb-v2#1155

Signed-off-by: Lin Gao <aoingl@gmail.com>
gaol added a commit to gaol/jaxb-ri that referenced this issue Feb 18, 2019
Original PR from: javaee/jaxb-v2#1155

Signed-off-by: Lin Gao <lgao@redhat.com>
gaol added a commit to gaol/jaxb-ri that referenced this issue Feb 18, 2019
Original PR: javaee/jaxb-v2#1155

Signed-off-by: Lin Gao <lgao@redhat.com>
@jonashackt
Copy link

Any progress on that? A PR is waiting for long now (in the old project javaee/jaxb-v2@d367678) - not really a big change, but would be great to see it in an upcoming release :)

gaol added a commit to gaol/jaxb-ri that referenced this issue Jun 10, 2019
Original PR: javaee/jaxb-v2#1155

Move the original fix down after IDREF check

Signed-off-by: Lin Gao <lgao@redhat.com>
gaol added a commit to gaol/jaxb-ri that referenced this issue Jul 2, 2019
Original PR: javaee/jaxb-v2#1155

Move the original fix down after IDREF check

Signed-off-by: Lin Gao <lgao@redhat.com>
@ehambuch
Copy link

ehambuch commented Jul 2, 2019

As we are also struggling with the same issue: is there any workaround known? Maybe setting the base class to a concrete one in the schema or something else?

@ehambuch
Copy link

ehambuch commented Jul 4, 2019

I have temporarily solved that issue in the following way: I edited the BiPRO-Schema-XSD in a way that every Element with an (abstract) STE-Type and maxOccurs=unbounded (which would be generated into a List in the corresponding JAXB-Class) is changed to maxOccurs=1. From a business perspective this works for us at the moment, nevertheless not a proper general workaround for the issue above.

@NiasSt90
Copy link

NiasSt90 commented Jul 4, 2019 via email

gaol added a commit to gaol/jaxb-ri that referenced this issue Nov 14, 2019
Original PR: javaee/jaxb-v2#1155

Move the original fix down after IDREF check

Signed-off-by: Lin Gao <lgao@redhat.com>
gaol added a commit to gaol/jaxb-ri that referenced this issue Nov 28, 2019
Original PR: javaee/jaxb-v2#1155

Move the original fix down after IDREF check

Signed-off-by: Lin Gao <lgao@redhat.com>
lukasj pushed a commit that referenced this issue Nov 28, 2019
Original PR: javaee/jaxb-v2#1155

Move the original fix down after IDREF check

Signed-off-by: Lin Gao <lgao@redhat.com>
@lukasj lukasj added this to the 2.3.3-b02 milestone Nov 29, 2019
@lukasj lukasj closed this as completed Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants