users@jaxb.java.net

How to force JAXB to generate correct output for derived classes

From: Qzpmwo <qzpmwo_at_gmail.com>
Date: Mon, 20 Jul 2009 10:05:17 -0700 (PDT)

Hi,

I'm having a problem with derived schema types and XML generated by JAXB.

Basically I'm having a schema like:

<xs:schema>
 
    <xs:complexType name="BaseType">
       <xs:sequence>
       </xs:sequence>
    </xs:complexType>
 
    <xs:complexType name="DerivedType">
       <xs:complexContent>
          <xs:extension base="BaseType">
             <xs:sequence>
             </xs:sequence>
          </xs:extension>
      </xs:complexContent>
    </xs:complexType>
 
    <xs:complexType name="ListType">
       <xs:sequence>
                <xs:element name="item" type="BaseType" minOccurs="0"
 maxOccurs="unbounded" />
       </xs:sequence>
    </xs:complexType>
 
    <xs:element name="base" type="BaseType" />
    <xs:element name="derived" type="DerivedType" />
    <xs:element name="list" type="ListType" />
 
</xs:schema>

XJC is used to generate java classes from this schema.

1) @XmlSeeAlso pointing to DerivedType class and @XmlRootElement
 annotations have been added to BaseType java class code
2) @XmlRootElement has been added to DerivedType java class code
3) @XmlRootElement has been added to ListType java class code

Right xml is produced when I'm using ListType

<list>
   <base xsi:type="DerivedType">...</base>
   ...
</list>

But when I'm trying to get single object of the DerivedType, I see wrong xml
(since I'm not using substitution group):

<derived>...</derived>

So question: Is there a way to force JAXB return correct xml?

Thanks in advance
--- Karen
-- 
View this message in context: http://www.nabble.com/How-to-force-JAXB-to-generate-correct-output-for-derived-classes-tp24573728p24573728.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.