atom feed2 messages in to marshal type XXX as an elem...
FromSent OnAttachments
Farrukh NajmiAug 15, 2007 1:43 pm 
Farrukh NajmiAug 15, 2007 7:12 pm 
Subject:unable to marshal type XXX as an element because it is missing an @XmlRootElement annotation
From:Farrukh Najmi (
Date:Aug 15, 2007 1:43:34 pm

Hi Kohsuke,

I am making my transition from JAXB 1.x to JAXB 2.x and just stumbled upon this error:

[com.sun.istack.SAXException2: unable to marshal type "XXX" as an element because it is missing an @XmlRootElement annotation]

You discuss this issue here: <>

I am very confused by this current behavior of xjc generated binding.

The most common use case in XML Schema based on my experience is one where you define a type FooType and then one or more elements Foo based on that type.

In JAXB 1.x a class FooType was generated for the FooType and a class generated for each element Foo that used the type. That seemed to work quite nicely.

In JAXB 2.x I am very surprised to discover that nearly *all* my FooTypes can no longer be marshalled and instead I get the above error.

This seems very questionable behavior based on my experience.

Perhaps I am missing something? What was wrong with the old behavior? Am I the only one who finds this to be questionable? How do other folks deal with the issue?

Note when I try the suggested workaround of using:

<jaxb:globalBindings> <xjc:simple/> </jaxb:globalBindings>

I got all kinds of errors like:

[ERROR] Property "XXX" is already defined. Use <property> to resolve this conflict.

I thought I knew JAXB pretty well but now I feel like a total newbie.

Hope you can help me understand what is going on and how to get the familiar JAXB 1.x behavior or equivalent.