Hi Allen,

That seems to me to be a matter of streaming, look here: 
http://camel.apache.org/stream.html

Regards,
Christian

-----Ursprüngliche Nachricht-----
Von: Bagwell, Allen F [mailto:afba...@sandia.gov]
Gesendet: Dienstag, 5. Dezember 2017 00:12
An: users@camel.apache.org
Betreff: Camel Jackson unmarshal behavior and object type

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.
----------------------------------------------------------------
innogy SE Vorsitzender des Aufsichtsrates: Dr. Werner Brandt
Vorstand: Peter Terium (Vorsitzender), Dr. Hans Buenting,
Dr. Bernhard Guenther, Martin Herrmann, Hildegard Mueller, Uwe Tigges
Sitz der Gesellschaft: Essen, Eingetragen beim Amtsgericht Essen,
Handelsregister-Nr. HRB 27091, USt-IdNr. DE304171711

Reply via email to