Apache camel and jackson

I am trying to use apache-camel, and I set up a base route that calls the HTTP service through the http4 component, converts the result through unmarshal (). json (JsonLibrary.Jackson) and then prints part of the response in the bean.

The problem I am facing is that it explodes at runtime when it gets into json unmarhsaller:

There is no type converter available for conversion from type: java.util.HashMap to the required type: com.xxx.MyType

The answer has the following format:

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

And my object model is similar:

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

Thus, it would seem that unmarshaller believes that the response is a hash map, whereas I want it to be marked in the structure of the object. Is there a way to get him to do what I want?

+7
source share
1 answer

I found the answer, posting it in case someone else comes across this. The route constructor should be configured as follows:

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

those. pass class type to json method.

+12
source

All Articles