Apache Camel: hidden JSON for POJO using camel methods

I have a REST server that sends JSON to the response body. I recently started reading about Apache Camel. I use the following to send requests to my REST service.

from("direct:start").setHeader("token", simple("234da"))
                            .to("http://localhost:8088/foo/bar/?foo1=bar1");

Now the answer will be JSON, is there a way that I get this JSON directly in POJO using some method before to()(something like this)?

to("http://localhost:8088/foo/bar/?foo1=bar1").toPOJO();

I would prefer a solution without Spring.

thank

+5
source share
2 answers

include the following dependency -

  <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jackson</artifactId>
        <version>2.14.1</version>
    </dependency>

Define JSON format in RouteBuilder class -

JacksonDataFormat jsonDataFormat = new JacksonDataFormat(Employee.class);

Also in the routebuilder class, use the above data formats as follows:

from("file:C:/inputFolder").doTry().unmarshal(xmlDataFormat).
        process(new MyProcessor()).marshal(jsonDataFormat).
        to("jms:queue:javainuse")

- Apache Camel - Marshalling/Unmarshalling XML/JSON Data

+2

Apache Camel POJO JSON .

:

 from("direct:start").setHeader("token", simple("234da"))
 .to("http://localhost:8088/foo/bar/?foo1=bar1")
 .unmarshal().json();

, json , .

+1

All Articles