阿帕奇骆驼和杰克逊 [英] apache camel and jackson

查看:55
本文介绍了阿帕奇骆驼和杰克逊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 apache-camel,我已经建立了一个基本路由,通过 http4 组件调用 http 服务,通过 unmarshal().json(JsonLibrary.Jackson) 转换结果,然后打印出部分bean 组件中的响应.

I'm trying out apache-camel, and I've set up a basic route that calls an http service via http4 component, transforms the result via unmarshal().json(JsonLibrary.Jackson), and then prints out part of the response in a bean component.

我遇到的问题是,当它到达 json unmarhsaller 时,它会在运行时爆炸:

The problem I'm having is that it blows up at runtime when it gets to the json unmarhsaller:

没有类型转换器可用于从类型:java.util.HashMap 转换为所需的类型:com.xxx.MyType

No type converter available to convert from type: java.util.HashMap to the required type: com.xxx.MyType

响应格式如下:

{"data":[{"x":"y"},{"x":"z"}]}

我的对象模型就像:

@lombok.Data
class Response {
    private List<Elem> data;
}

@lombok.Data 
class Elem {
    private String x;
}

因此,解组器似乎认为响应是一个哈希映射,而我希望它解组为对象结构.有没有办法让它做我想做的事?

So it would appear that the unmarshaller thinks the response is a hash map, whereas I want it to unmarshal into an object structure. Is there a way to get it to do what I want?

推荐答案

找到答案,发布以防其他人遇到此问题.路线构建器应设置为:

Found the answer, posting in case anyone else runs into this. The route builder should be setup like:

from("direct:start").to("http4://...").unmarshal().json(JsonLibrary.Jackson,com.xxx.Response)
.to("bean:com.xxx.MyResponseEchoer")

即将类类型传递给 json 方法.

I.e. pass the class type to the json method.

这篇关于阿帕奇骆驼和杰克逊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆