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

Problems with abstract classes and @XMLValue #620

Closed
Tomas-Kraus opened this issue Mar 23, 2009 · 15 comments
Closed

Problems with abstract classes and @XMLValue #620

Tomas-Kraus opened this issue Mar 23, 2009 · 15 comments

Comments

@Tomas-Kraus
Copy link
Member

Problems with abstract classes and @XMLValue
JAXB 2.1.10

According to the following schema unmarshalling a valid XML results in an
java.lang.InstantiationException, caused by instancing the abstract class
TypeEnumeration.

<xsd:schema xmlns:mime="http://www.w3.org/2005/05/xmlmime"
xmlns="http://namespace" attributeFormDefault="qualified"
elementFormDefault="qualified" targetNamespace="http://namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="TypeEnumeration" abstract="true">
xsd:simpleContent
<xsd:extension base="xsd:string" />
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="TypeEnumerationBase">
xsd:simpleContent
<xsd:restriction base="TypeEnumeration">
<xsd:enumeration value="00">
xsd:annotation
xsd:documentationNone</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="01">
xsd:annotation
xsd:documentationFirst Element</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>
<xsd:element name="SomeElement">
xsd:complexType
xsd:sequence
<xsd:element name="Type" type="TypeEnumeration" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Example XML:

<tns:SomeElement xmlns:tns="http://namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:Type xsi:type="tns:TypeEnumerationBase">01</tns:Type>
</tns:SomeElement>

Vice versa marshalling an Java object results in an invalid XML due to the given
schema TypeEnumeration.xsd:

01

The abstract element Type is used, but I expected something like
01</ Type>.

I need to preserve the structure of inherence, due to be compatible to other
projects and data exchange.

Changing the @XMLValue Annotation to @XMLAttribute leads to the expected
behaviour. I get an element.

So inherence with @XMLValue fails …

Environment

Operating System: All
Platform: All

Affected Versions

[2.1.9]

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
Reported by dburgard

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
File: example.zip
Attached By: dburgard

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
dburgard said:
Created an attachment (id=302)
Example code and generated classes.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
dburgard said:
Related to issue 619.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
snajper said:
One more connected to 619, so assigning to Pavel.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
@pavelbucek said:

      • Issue 619 has been marked as a duplicate of this issue. ***

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
@pavelbucek said:

      • Issue 689 has been marked as a duplicate of this issue. ***

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
@pavelbucek said:
this is far more complex than I initially thought. I have a patch but it breaks lots of our tests; needs more
investigation

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
@pavelbucek said:
fixed in trunk

still not foolproof, but it definitely should work for this kind of usages.
however, there are still some limitations (with nillable elements) but it works
in most cases.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
Marked as fixed on Monday, December 14th 2009, 4:39:19 pm

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
@pavelbucek said:
I had to "revert" this fix.. not actually revert, but disable it from "standard" jaxb and it can be enabled only by setting JAXBContext property JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING (or "com.sun.xml.bind.improvedXsiTypeHandling") to true.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
snajper said:
I see the final version commited to 2.2.4

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
bob99 said:
The problem is only partially solved, see bug #890.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JAXB-620

@Tomas-Kraus
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant