开发者

apache camel and jackson

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 开发者_StackOverflowcomponent.

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?


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")

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜