I am using camel-jackson to marshal/unmarshal in a blueprint route for use with
a CXF rest client. The rest call expects a JSON string and returns one in its
response.
I can do an unmarshal like in the examples provided on the Camel Jackson page
and it works fine, but I'm having trouble with the marshal element.
<dataFormats>
<json id="jsonSend" library="Jackson"
unmarshalTypeName="my.app.json.SendMessage" />
<json id="jsonReceive" library="Jackson"
unmarshalTypeName="my.app.json.ReturnMessage" />
</dataFormats>
...
<route>
...
<marshal ref="jsonSend"/>
<log message="${body}" loggingLevel="INFO"/> <!- prints the JSON string -->
<to uri="cxfrs://bean:rsClient" id="clientEndpoint"/>
<unmarshal ref="jsonReceive"/>
<log message="${body}" loggingLevel="INFO"/> <!- prints a reference to a
ReturnMessage object -->
...
</route>
When I attempt to marshal, I have a SendMessage object as my (in) message body.
After the marshalling occurs, the logging message prints out ${body} as an
equivalent JSON string.
At this point, however, the route hangs and the rest call is never reached.
It turns out to fix this, I have to put
<convertBodyTo type="java.lang.String"/>
after the marshal element.
Is this expected behavior? I didn't see a need for this in the examples.
It occurred to me that the logging element could be calling a toString method
under the hood, so what I'm seeing in the log is not really the object that is
present. However it seems odd to me that after a call to marshal that the
${body} is not a String since the whole point is to serialize the POJO.
The unmarshal step definitely converts the return JSON string to a POJO, and
the log statement following it indicates that ${body} is a ReturnMessage object.