Bionix1441
Bionix1441

Reputation: 2319

How to get a JSON object from a file and map it to a Java class using Apache Camel routes?

I have created a RequestRoute which extends RouteBuilder:

@Component
public class RequestRoute extends RouteBuilder {

@Override
public void configure() throws Exception {
    from("file:input?noop=true").to(User.class);
}

And in the main class, I have added the route created above to Camel context:

  @SpringBootApplication
  public class DemoApplication {

  @SneakyThrows
  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);

    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RequestRoute());
  }

}

How can I get a JSON object from a file inside the folder and transform it to a Class using Camel routes?

Upvotes: 0

Views: 811

Answers (1)

Sneharghya Pathak
Sneharghya Pathak

Reputation: 1060

You need to do an unmarshal.

from("file:input?noop=true")
.unmarshal().json(JsonLibrary.Jackson, User.class)

Upvotes: 1

Related Questions