users@jaxb.java.net

Re: jaxb1 problem with complex-types vs elements

From: Ed Mooney <Ed.Mooney_at_Sun.COM>
Date: Thu, 22 Jun 2006 13:35:06 -0400

Hi Christoph,

Could you send along a test case?

Thanks,
-- 
Ed Mooney         |Sun Microsystems, Inc.|Time flies like
Java Web Services |UBUR02-201            |an arrow, but
Ed.Mooney_at_Sun.COM |1 Network Drive       |fruit flies like
781-442-0459      |Burlington, MA  01803 |a banana. Groucho
Christoph Sturm wrote:
> 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