3

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.

Nick Spacek
  • 4,717
  • 4
  • 39
  • 42

2 Answers2

2

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:

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • One strange thing is that earlier we had an attribute storing the value of an enum that we're using as the @XmlDiscriminatorNode and when both the attribute and annotation specify the same name the attribute appears twice in the XML, causing XML parsers to barf. I would expect that we'd get an exception instead when the class is loaded into the JAXBContext. – Nick Spacek May 02 '12 at 17:25
1

Your discriminator is an attribute, so I think you just need to add an "@":

@XmlDiscriminatorNode("@thetype")
public abstract class A {}

This blog post by Blaise Doughan contains some more information and an example.

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118