title: How to configure Jackson ObjectMapper for Camel in Spring Boot
body: <p>I am trying to serialize and deserialize POJOs to and from JSON on Camel routes using Jackson. Some of these have Java 8 LocalDate fields, and I want them to be serialised as YYYY-MM-DD string, not as an array of integers.</p>
  
  <p>We only use Java configuration for our Spring Boot application, so no XML Camel configuration.</p>
  
  <p>I have successfully created an ObjectMapper that does what I want, which is being used by other parts of our system by adding this to our dependencies:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.datatype&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-datatype-jsr310&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>and this to our application configuration:</p>
  
  <pre><code>@Bean
  public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
      return builder
              .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
              .build();
  }
  </code></pre>
  
  <p>Example outgoing REST route:</p>
  
  <pre><code>@Component
  public class MyRouteBuilder extends RouteBuilder {
  
      @Override
      public void configure() throws Exception {
  
          restConfiguration().component("servlet").contextPath("/mycontext")
                  .port(8080).bindingMode(RestBindingMode.json);
  
          rest("/myendpoint)
                  .get()
                  .route()
                  .to("bean:myService?method=myMethod()");
      }
  }
  </code></pre>
  
  <p>Example incoming message route:</p>
  
  <pre><code>@Component
  public class MyRouteBuilder extends RouteBuilder {
  
      @Autowired
      private MyBean myBean;
  
      @Override
      public void configure() {
          from(uri)
                  .unmarshal().json(JsonLibrary.Jackson)
                  .bean(myBean);
      }
  }
  </code></pre>
  
  <p>However, by default Camel creates its own ObjectMapper instances so does not pick up on either the JSR310 serializers/deserializers that <code>Jackson2ObjectMapperBuilder</code> adds automatically, or the disabled <code>WRITE_DATES_AS_TIMESTAMPS</code> feature. I have read the <a href="http://camel.apache.org/json.html" rel="noreferrer">Camel JSON</a> documentation, but it does not show how to add a custom DataFormat using Spring configuration, or how to apply a global customisation for all types.</p>
  
  <p>So how can I tell Camel to use my ObjectMapper, using only Spring Boot Java configuration?</p>