cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: @XMLRootElement for parameters in REST method signatures
Date Fri, 01 Jul 2011 09:51:36 GMT

On Thu, Jun 30, 2011 at 11:35 PM, dponos <> wrote:
> Thank you Stephen,  your information definitely helps.  I am able to work
> around the issue this way.
> Over the last day, I experimented more with the the classes that I was able
> to generate the @XmlRootElement annotation for, but still had issues when
> using them as parameters in my REST service method signatures.
> I looked closer into the error message I was getting, messages like this:
> JAXBException occurred : unexpected element (uri:"", local:"Foo"). Expected
> elements are <{}Foo>,.....
> I noticed that the unexpected element has a namespace of "local" and the
> expected element is there, but has a namespace value that came from the XSD.
> I performed an experiment by copying "Foo" to a different package with no
> other changes other than changes the name to something like Foo2, and the
> problem went away.

I guess this is because JAXB understands from the generated
ObjectFactory that Foo is actually namespace qualified and enforces
it. Renaming it to Foo2 class in a diff package works because Foo2 has
no @XMLRootElement and unmarshalling XMLType-annotated classes with
JAXBElement  probably does not need to know the root element name.

By the way I reckon the reason you got the error earlier on even after
forcing the JAXB generator to add @XMLRootElement was caused by the
unqualified content coming from the client, as you explained below...

> So this is leading me to believe that my issue is really some sort of
> namespace issue.   My client will be a javascript client.  I am currently
> testing with Firefox Poster, with the json object in the request body.  The
> json object looks like this :
> {
>    "Foo":
>        {
>            "name":"bar"
>        }
> }
> There is nothing in the client that is specifying a namespace.  I've been
> told that the client does not specify a namespace for the object.
> So I am wondering if there is some sort of filter/interceptor I need to
> write or configure in order to match "Foo" with "{}Foo"

It does look like that the original problem you reported is caused by
the fact the client is submitting an unqualified response.
Starting with CXF 2.4.0 one can solve this issue by configuring
TransformFeature [1] on the server side (and/or client side if
needed), example, when using Spring:

<bean id="transformFeature" class="org.apache.cxf.feature.StaxTransfromFeature">
  <property name="inTransformElements">
      <entry key="Foo" value="{}Foo"/>

and then link to it:
       <ref bean="transformFeature"/>

This feature instance will qualify a chosen element in the coming XML
stream coming from default JSONProvider, before this specific element
is consumed by JAXB

Hope it helps


> --
> View this message in context:
> Sent from the cxf-user mailing list archive at

Sergey Beryozkin

Application Integration Division of Talend

View raw message