阿帕奇骆驼和杰克逊
我正在尝试 apache-camel,并且设置了一个基本路由,通过 http4 组件调用 http 服务,通过 unmarshal().json(JsonLibrary.Jackson) 转换结果,然后打印出部分响应在 bean 组件中。
我遇到的问题是,当它到达 json unmarhsaller 时,它会在运行时爆炸:
没有类型转换器可用于从类型:java.util.HashMap 转换为所需类型:com.xxx.MyType
响应的格式如下:
{"data":[{"x":"y"},{"x":"z"}]}
我的对象模型如下:
@lombok.Data
class Response {
private List<Elem> data;
}
@lombok.Data
class Elem {
private String x;
}
因此,解组器认为响应是哈希映射,而我希望将其解组为对象结构。有没有办法让它做我想做的事?
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.
The problem I'm having is that it blows up at runtime when it gets to the json unmarhsaller:
No type converter available to convert from type: java.util.HashMap to the required type: com.xxx.MyType
The response is of this format:
{"data":[{"x":"y"},{"x":"z"}]}
And my object model is like:
@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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到答案,发布以防其他人遇到这个问题。路由构建器应该设置如下:
即将类类型传递给 json 方法。
Found the answer, posting in case anyone else runs into this. The route builder should be setup like:
I.e. pass the class type to the json method.