I’m using eclipselink-2.3.2. My package is annotated:
@XmlSchema(namespace = "http://example.com/namespace", elementFormDefault = XmlNsForm.QUALIFIED)
I have the following classes:
@XmlRootElement
public class Box {
private A item; // and getter/setter
}
@XmlDiscriminatorNode("@thetype")
public abstract class A {}
@XmlDiscriminatorValue("b")
public class B extends A {}
@XmlDiscriminatorValue("c")
public class C extends A {}
When I try to deserialize valid XML like this:
<box xmlns="http://example.com/namespace"><a thetype="b" /></box>
I get the descriptive exception:
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class indicator field from database row [UnmarshalRecord()]
If I remove the @XmlSchema from the package and the xmlns attribute from the root element, it works. If I change from QUALIFIED to UNQUALIFIED, it works as long as I feed it the ugly prefixed XML.
I assumed that the unprefixed would work since it still declares the default namespace, but although there is no exception the field remains null.
After stepping through the EclipseLink code, I can see that when QNameInheritancePolicy.classFromRow calls UnmarshalRecord.get, it is trying to access the attribute “thetype” under the namespaceURI “http://example.com/namespace”.
When I change the XmlScehma elementFormDefault to UNQUALIFIED, the namespaceURI comes back null and the attribute is properly retrieved.
This is a bug in EclipseLink JAXB (MOXy). You can track our progress on this issue using the link below. I already have a fix attached to the bug, I’ll check it in once the test cases have finished running.
UPDATE
This bug has now been fixed. You can try it out by obtaining one of the EclipseLink 2.4.0 nightly builds starting April 30th, 2012: