title: Unmarshaling (JSON) in apache camel
body: <p>I am new in apache camel. And I wanna do some simple task using apache camel. I have json data available on this url <a href="http://localhost:8080/users/" rel="nofollow">http://localhost:8080/users/</a>. There are json data from my rest service. But I wanna get this json data and unmarshal it to POJO using apache camel and write some data to txt file. But my app starts and then doesnt't stop.</p>
  
  <p>Here is my JSON data available on <a href="http://localhost:8080/users/" rel="nofollow">http://localhost:8080/users/</a><br>
  <div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>[{"id":1,"login":"admin","password":"admin","passwordAgain":null,"email":"admin@admin.com","firstName":"Admin","lastName":"Adminovich","birthday":"2010-10-10","role":{"id":1,"name":"admin"}},
  {"id":5,"login":"Snow123","password":"1111","passwordAgain":null,"email":"john@snow.com","firstName":"John","lastName":"Snow","birthday":"2010-10-10","role":{"id":2,"name":"user"}}]</code></pre>
  </div>
  </div>
  </p>
  
  <p>spring.xml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:camel="http://camel.apache.org/schema/spring"
         xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
      
  
      &lt;bean id="MyRouteBuilder" class="MyRouteBuilder" init-method="restart"&gt;
  
      &lt;/bean&gt;
  
      &lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
  
          &lt;routeBuilder ref="MyRouteBuilder"/&gt;
  
      &lt;/camelContext&gt;
  
  &lt;/beans&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>MyRouteBuilder</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import Mapping.User;
  import Mapping.Users;
  import org.apache.camel.Exchange;
  import org.apache.camel.Processor;
  import org.apache.camel.builder.RouteBuilder;
  import org.apache.camel.main.Main;
  import org.apache.camel.component.restlet.RestletConstants;
  import org.apache.camel.model.dataformat.JsonLibrary;
  import org.restlet.Response;
  import org.restlet.data.MediaType;
  import org.restlet.data.Status;
  
  
  
  public class MyRouteBuilder extends RouteBuilder {
  
      private String routePort = null;
      private String routeAnswer = null;
  
      public void restart() {
          String start = "Route Property Placeholder Example started on port" + " 8080" + "!";
          System.out.println(start);
      }
  
      public void configure() throws Exception {
          from("timer:foo?repeatCount=1").to("http://10.10.34.145:8080/users/").unmarshal().json(JsonLibrary.Jackson, Users.class ).log("STARTED!")
                  .process(new Processor() {
                      public void process (Exchange exchange) throws Exception {
                          Users usersList = exchange.getIn().getBody(Users.class);
                          exchange.getIn().setBody(usersList.usersList);
                          System.out.println(usersList.usersList.size());
                      }
                  }).to("file:///home/name/username/Desktop/camel.txt").stop();
  
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>User</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package Mapping;
  
  import com.google.gson.FieldNamingStrategy;
  
  import java.lang.reflect.Field;
  
  public class User {
  
      public User() {
  
      }
  
      private int id;
      private String login;
      private String password;
      private String passwordAgain;
      private String email;
      private String firstName;
      private String lastName;
      private String birthday;
  
      public void setId(int id) {
          this.id = id;
      }
  
      public void setLogin(String login) {
          this.login = login;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public void setPasswordAgain(String passwordAgain) {
          this.passwordAgain = passwordAgain;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public void setBirthday(String birthday) {
          this.birthday = birthday;
      }
  
      public void setRole(String role) {
          this.role = role;
      }
  
      public int getId() {
          return id;
      }
  
      public String getLogin() {
          return login;
      }
  
      public String getPassword() {
          return password;
      }
  
      public String getPasswordAgain() {
          return passwordAgain;
      }
  
      public String getEmail() {
          return email;
      }
  
      public String getFirsteName() {
          return firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public String getBirthday() {
          return birthday;
      }
  
      public String getRole() {
          return role;
      }
  
      private String role;
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Users</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package Mapping;
  
  import java.util.ArrayList;
  import java.util.List;
  public class Users {
  
      public List&lt;User&gt; usersList = new ArrayList&lt;User&gt;();
  }</code></pre>
  </div>
  </div>
  
  Main</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import org.apache.camel.main.Main;
  
  public class MainClass {
  
      public static void main(String[] args) {
          Main main = new Main();
          main.enableHangupSupport();
  
          MyRouteBuilder rb = new MyRouteBuilder();
          main.addRouteBuilder(rb);
          try {
              main.run(args);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  }</code></pre>
  </div>
  </div>
  </p>