Reputation: 4463
I configured my rest service to implement content negotiation through Variant. On jersey all works fine but on apache cxf something goes wrong.
No message body writer has been found for class ContentType: application/xml
It seems thath when I construct the response as xml type it cannnot find the correct body writer.
I configured jax-rs with jacksonJaxbJsonProvider and all works great with json databind.
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
</jaxrs:providers>
cxf-rt-frontend-jaxrs version 3.0.3 jackson-databind: 2.4.2
Any idea?
Upvotes: 0
Views: 352
Reputation: 10004
Add a @XmlRootElement(name="order")
generated xml cannot be <orderId>data<orderId>
, it should have root element. Thus updated code would look like
@XmlRootElement(name="order")
@XmlType(propOrder = { "orderId"})
public class OrderForConfirmationEmail implements Serializable {
@XmlElement
public long getOrderId() {
long orderId = new Random().nextLong();
return orderId;
}
}
Generated xml is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><order xmlns="http://com.kp.swasthik/so/schema">
<orderId>369317779145370211</orderId>
</order>
and json is
{"orderId":6812414735706519327}
Upvotes: 1