users@jaxb.java.net

jaxb1 problem with complex-types vs elements

From: Christoph Sturm <christoph.sturm_at_gmail.com>
Date: Wed, 21 Jun 2006 13:42:32 +0200

hey all!

I am experiencing a strange effect in jaxb1:

imagine i have one complex type and one element

<xs:complex-type name="UserType" ....>

<xs:element name="User" type="UserType"/>

jaxb now creates a User class for me that extends UserType

now i have another element that uses UserType

<xs:element name="TypeThatContainsUserType">
<xs:complex-type>
<xs:element name="myUser" type="UserType"/>
</...>

now I have TypeThatContainsUserType class, with a setMyUser(UserType)

User extends UserType so i can pass a user to this setter.

but when i then try to marshall this type i get a document that doesnt
validate, and i get an error message that looks something like this:

org.xml.sax.SAXException: Invalid element in ....UserType - user


so my question is basically: why does the User class extend the
UserType class, if the marshalling creates incorrect xml then?

is there a workaround?
am i doing something stupid?
is that also the case in jaxb2?

thanks
 chris
-- 
christoph.sturm_at_gmail.com