Problems with abstract classes and @XMLValue · Issue #620 · javaee/jaxb-v2 (original) (raw)

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:complexType name="TypeEnumerationBase">
xsd:simpleContent
<xsd:restriction base="TypeEnumeration">
<xsd:enumeration value="00">
xsd:annotation
xsd:documentationNone


<xsd:enumeration value="01">
xsd:annotation
xsd:documentationFirst Element





<xsd:element name="SomeElement">
xsd:complexType
xsd:sequence
<xsd:element name="Type" type="TypeEnumeration" />



Example XML:

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

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]