Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 633
Kevin Avatar asked Jun 28 '11 16:06

Kevin


1 Answers

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.

like image 169
Kevin Avatar answered Sep 24 '22 00:09

Kevin