I tried to update following code from Apache CXF 2.4.6 to Apache CXF 2.5.3:
@Path("/myresource")
public class MyResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Root get() {
Root root = new Root();
root.setName("Test");
return root;
};
}
@XmlRootElement(namespace = "http://www.my.org", name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {
@XmlElement
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Spring configuration:
<jaxrs:server address="/myPath" id="myID"
<jaxrs:serviceBeans>
<ref bean="myResource" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"/>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
</jaxrs:providers>
</jaxrs:server>
With Apache CXF 2.4.6 and Jackson 2.2.3 I get the right JSON:
{"name":"Test"}
With Apache CXF 2.5.3 and Jackson 2.2.3 I get a wrong JSON:
{"ns1.root":{"name":"Test"}}
Client:
JAXRSClientFactoryBean jaxrsClientFactoryBean = new JAXRSClientFactoryBean();
jaxrsClientFactoryBean.setAddress(address);
jaxrsClientFactoryBean.setProviders(Arrays.asList(new JacksonJaxbJsonProvider(), new JAXBElementProvider()));
jaxrsClientFactoryBean.setServiceClass(MyResource.class);
MyResource myResource = jaxrsClientFactoryBean.create(MyResource.class);
Root root = myResource.get();
On client-side (proxy client) I get an exception:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"ns1.root"). Expected elements are <{http://www.my.org}root>
I read the migration guide, but found no answer for my problem.