7

I'm implementing a REST service using Camel's cxfrs component. Various examples I've seen around the inets say I can get the service to return a JSON serialization of the object in question using a cxf:providers tag, like so

<cxf:rsServer id="rsServer" address="${CXFserver}${service}" serviceClass="org.trinityhealth.esb.PersonService"
    loggingFeatureEnabled="true" loggingSizeLimit="20">
    <cxf:providers>
        <bean id="jsonHandler" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
    </cxf:providers>
</cxf:rsServer>

This compiles and deploys just fine. But no matter what variant of this config I try, the service responds with "No message body writer has been found for response class Person". The Person class has a "@XmlRootElement(name = "Person")" annotation in it, which I guess is great if I wanted XML produced. But I don't - I want JSON. Jackson has a ton of annotations, do I need to add one to the Person class to get my service to realize I want the class serialized by the Jackson writer?

  • I never used camel as a server. Using CXF, JacksonJsonProvider should be able to serialize plain objects. Try also `JacksonJaxbJsonProvider` to deal with Jaxb annotations – pedrofb Apr 03 '19 at 08:31

1 Answers1

0

I don't know Camel that well, but typically Jackson does NOT require root annotation, unlike JAXB (partly since JSON structure does not require name for root type), so it seems unlikely you would such annotation. I am guessing that rather the registration does not succeed for some reason.

StaxMan
  • 113,358
  • 34
  • 211
  • 239