users@jaxb.java.net

Re: Getting JAXB to instantiate your subclasses

From: Ryan Shoemaker - JavaSoft East <Ryan.Shoemaker_at_sun.com>
Date: Mon, 07 Apr 2003 13:51:58 -0400

Allister Bertram wrote:
> I can get the code to compile, and I can unmarshal my XML into Java
> objects.
>
> The problem is that only the highest-level instances are unmarshalled into
> my Impl subclasses.
>
> When my XML document contains:
>
> <ElementA>
> <ElementAA>..</ElementAA>
> <ElementBB>..</ElementBB>
> <ElementCC>..</ElementCC>
>
> My ElementA is unmarshalled into a MyAImpl, but my ElementAA is
> unmarshalled into an AAImpl, my ElementBB into a BBImpl, etc.
>

Are you placing the <implClass> customization on the element declarations
or the anonymous complexType declarations? Do you have:

    <xs:element name="ElementA">
      <xs:complexType>
        <xs:annotation><xs:appinfo>
          <jxb:implClass name="com.acme.foo.MyAImpl"/>
        </xs:appinfo></xs:annotation>
        ...
      </xs:complexType>

or:

    <xs:element name="ElementA">
      <xs:annotation><xs:appinfo>
        <jxb:implClass name="com.acme.foo.MyAImpl"/>
      </xs:appinfo></xs:annotation>
      <xs:complexType>
        ...
      </xs:complexType>

If you're placing the customization on the element rather than the type,
that might explain the problem.

--Ryan


> When my XML document contains:
>
> <ElementAA>
> <ElementARef>..</ElementARef>
> </ElementAA>
> <ElementBB>
> <ElementARef>..</ElementARef>
> </ElementBB>
>
> My ElementAA is then unmarshalled into a MyAAImpl, my ElementBB into a
> MyBBImpl, etc.
>
>
>
>