Camel 将InputStreamCache转换为POJO

3htmauhk  于 11个月前  发布在  Apache
关注(0)|答案(2)|浏览(115)

我正在尝试将JSONInputStreamCache响应转换为Apache Camel中的POJO,如下所示:

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

字符串
但是,我得到以下例外:

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]


有没有什么方法可以使用convertBodyTo组件直接将StreamCache有效负载转换为POJO?我不想写一个显式的转换器。
注意:我知道unmarshal组件。我想确认是否可以使用convertBodyTo实现相同的功能。

olhwl3o2

olhwl3o21#

您需要添加camel-jackson作为依赖项,因为如果您打开它,它能够从JSON有效负载转换为POJO。
请参见http://camel.apache.org/json一节 * 将Jackson与Camel的TypeConverters集成 *

fzwojiic

fzwojiic2#

我遇到了maven依赖问题。对于Sping Boot 应用程序,您可以使用“camel-jackson-starter”而不是“camel-jackson”。

相关问题