title: Serialize java.time.localdate into json using Jackson
body: <p>I'm writing a Java 8 Spring MVC application that communicates with a legacy Progress OpenEdge application using a REST service (I'm using Spring's RestTemplate for this). The data I need to read from and write to the Progress application contains some dates. In the Java application, I use a java.time.LocalDate datatype to represent these fields and I'm using Jackson to serialize / deserialize the data into / from Json.</p>
  
  <p>The problem I'm having is the following. When I send data from the Progress Application, the date is send as '2015-01-02' and stored in my Java entity as a LocalDate as expected. When the data is send to the web front-end the Json also contains the date in the same format. When I change information in the web front-end and apply it, it's also send back to the Java application as '2015-01-02' and again stored as a LocalDate without problems. But when I than send the data onwards to the Progress application, the Json I receive doesn't contain the date as '2015-01-02' but as an array containing three fields (2015.0, 1.0, 2.0) and the Progress application is unable to assign this back to a date field in the database.</p>
  
  <p>Offcourse I could write a conversion on the Progress side to convert the array back into a date, but I'd like to avoid this as I would expect the date to always be send in the ISO 8601 format.</p>
  
  <p>According to the information I find on Jackson, a java.time.LocalDate is represented as an array when WRITE_DATES_AS_TIMESTAMPS is enabled, but I have this disabled (And when the date is send to the web front-end, it's not being send as an array...)</p>
  
  <p>Here is some relevant code:</p>
  
  <p>The CustomObjectMapper:</p>
  
  <pre><code>@Service
  public class CustomObjectMapper extends ObjectMapper
  {
    public CustomObjectMapper()
    {
      this.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
                     false);
    }
  }
  </code></pre>
  
  <p>The configuration in my servlet.xml</p>
  
  <pre><code>&lt;mvc:annotation-driven&gt;
    &lt;mvc:message-converters&gt;
      &lt;bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;
        &lt;property name="objectMapper" ref="customObjectMapper"/&gt;
      &lt;/bean&gt;
    &lt;/mvc:message-converters&gt;
  &lt;/mvc:annotation-driven&gt;
  
  &lt;bean id="customObjectMapper" class="com.msoft.utility.CustomObjectMapper"/&gt;
  </code></pre>
  
  <p>The field definition:</p>
  
  <pre><code>@JsonDeserialize(using = LocalDateDeserializer.class)
  @JsonSerialize(using = LocalDateSerializer.class)
  private LocalDate deliveryDate;
  </code></pre>
  
  <p>I'm using Java 8 with Spring 4.1.5 and Jackson 2.5.1.</p>
  
  <p>Any tips how I could get this working or were to search for a solution would be greatly appreciated as I've already been working on this for almost 2 days...</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Some extra info...</p>
  
  <p>I've included the Jackson JSR-310 module in my pom.xml. Here is the releveant part of my pom file...</p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
    &lt;version&gt;2.5.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
    &lt;version&gt;2.5.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
    &lt;version&gt;2.5.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.datatype&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-datatype-jsr310&lt;/artifactId&gt;
    &lt;version&gt;2.5.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
    &lt;version&gt;4.1.5.RELEASE&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
    &lt;type&gt;jar&lt;/type&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
    &lt;version&gt;4.1.5.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
    &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
    &lt;version&gt;1.7.2.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Also, if I understood correctly, Spring will register this module automatically when it's detected. See the info on <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.html" rel="noreferrer">Jackson2ObjectMapperFactoryBean</a></p>
  
  <blockquote>
    <p>Note that Jackson's JSR-310 and Joda-Time support modules will be
    registered automatically when available (and when Java 8 and Joda-Time
    themselves are available, respectively).</p>
  </blockquote>
  
  <p>So I don't think I should have to do anything else to get this working correctly, but obviously I'm still missing something... </p>