users@jaxb.java.net

Re: java 5 enum type serialization problem

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 17 Oct 2006 09:46:38 +0200

Hi.

>> Add <xs:element name="MyEnum" type="enumType"/> to your schema.
>> Your enumType by itself is just a type. You can only marshal an element.
>>
> Thanks for hint, but the result I got is the same as if I would add this
> enum type declaration to my jaxb.index file, so I unfortunately got:
>
> javax.xml.bind.MarshalException
> - with linked exception:
> [com.sun.istack.SAXException2: unable to marshal type
> "generated.EnumType" as an element because it is missing an
> @XmlRootElement annotation]

You need to create a JAXBElement out of your instance:

ObjectFactory.createMyEnum(myEnum)

which will effectively be:

new JAXBElement(new QName("MyEnum"), EnumType.class, null, myEnum)

Bye.
/lexi