users@jaxb.java.net

Re: Inheritance seems broken

From: Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com>
Date: Mon, 18 Apr 2005 09:20:18 -0700

Brian Pontarelli wrote:
> I just pulled down the latest JAXB 2.0 EA release and started converting
> my classes to use it. Classes that were previously working are not
> longer working for some reason.
>
> I have two classes:
>
> public class Response {
> private Status status;
> }
>
> @XmlType(name = "", propOrder = {"status", "data"})
> public class AuthenticationResponse extends Response {
> private Data data;
> }
>
> My XSD is something like this (I coded these classes by hand, so the XSD
> isn't really used, but still important):
>
> <xsd:element name="authenticateResponse">
> <xsd:complexType mixed="false">
> <xsd:sequence>
> <xsd:element name="status" type="status"/>
> <xsd:element name="data" type="data" minOccurs="0"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
>
> I'm getting this error when running a marshalling operation:
>
> Property status appears in @XmlType.propOrder, but no such property
> exists this problem is related to the following location:
> at AuthenticateResponse
> at public AuthenticateResponse ObjectFactory.createAuthenticateResponse()
> at ObjectFactory

the properties of the base class always appear before those of a derived
class, so I think you only need to say propOrder={"data"}.

And currently, the order properties show up in XML is the order they are
defined in the Java source code, so actually you don't have to write
propOrder at all (although there's a quite lengthy tricky issue behind this)

> It appears that JAXB no longer allows me to refactor my elements into
> base classes for some reason. It cannot find the status member even
> though it exists on the Response base class. This used to work with the
> previous JAXB 2.0 release. Am I missing something?

I think the current behavior is correct. I think requiring members of
the base type to be before those of the derived types is a reasonable
limitation, and I don't think you want to list all the base type
property names every time you define propOrder for a derived type.

How do you think?

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com