Search code examples
apache-camelunmarshallingjbossfuse

Converting InputStreamCache to POJO


I'm trying to convert a JSON response, which is in InputStreamCache format, to POJO in Apache Camel, as follows:

<convertBodyTo type="com.temp.MyPojo"/>

But, I'm getting following exception:

No body available of type: model.so.response.MyResponse but has value: 
org.apache.camel.converter.stream.InputStreamCache@3a689bf8 of type: 
org.apache.camel.converter.stream.InputStreamCache on: Message: [Body is 
instance of org.apache.camel.StreamCache]. Caused by: No type converter 
available to convert from type: 
org.apache.camel.converter.stream.InputStreamCache to the required type: 
model.so.response.MyResponse with value 
org.apache.camel.converter.stream.InputStreamCache@3a689bf8. 
Exchange[Message: [Body is instance of org.apache.camel.StreamCache]]. 
Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type 
converter available to convert from type: 
org.apache.camel.converter.stream.InputStreamCache to the required type: 
model.so.response.MyResponse with value 
org.apache.camel.converter.stream.InputStreamCache@3a689bf8]

Is there any way by which I can directly convert StreamCache payload to POJO using convertBodyTo component? I don't want to write an explicit convertor.


Note : I'm aware of unmarshal component. I want to confirm whether the same functionality can be achieved using convertBodyTo.


Solution

  • You need to add camel-jackson as dependency as it has the ability to convert from JSon payload to POJOs if you turn it on.

    See http://camel.apache.org/json the section Integrating Jackson with Camel's TypeConverters