我正在尝试将JSON
的InputStreamCache
响应转换为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
实现相同的功能。
2条答案
按热度按时间olhwl3o21#
您需要添加camel-jackson作为依赖项,因为如果您打开它,它能够从JSON有效负载转换为POJO。
请参见http://camel.apache.org/json一节 * 将Jackson与Camel的TypeConverters集成 *
fzwojiic2#
我遇到了maven依赖问题。对于Sping Boot 应用程序,您可以使用“camel-jackson-starter”而不是“camel-jackson”。