title: Serialize LocalDate and LocalDateTime as Unix timestamps
body: <p>I'm moving from using <code>java.sql.Timestamp</code> and <code>java.util.GregorianCalendar</code> to employ <code>java.time.*</code> new classes in a Spring MVC application.</p>
  
  <p>So I changed every</p>
  
  <pre><code>private GregorianCalendar field;
  </code></pre>
  
  <p>to </p>
  
  <pre><code>private LocalDate field;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>private LocalDateTime field;
  </code></pre>
  
  <p>But now when serializing those beans, they get serialized like this:</p>
  
  <pre><code>"field": {
        "year": 1970,
        "month": "JANUARY",
        "dayOfMonth": 18,
        "dayOfWeek": "SUNDAY",
        "era": "CE",
        "dayOfYear": 18,
        "leapYear": false,
        "monthValue": 1,
        "chronology": {
          "id": "ISO",
          "calendarType": "iso8601"
        }
      },
  </code></pre>
  
  <p>I found answers to other questions that mention to add a dependency to <a href="http://search.maven.org/#search|ga|1|a%3A%22jackson-datatype-jsr310%22" rel="noreferrer">jackson-datatype-jsr310</a> and obtained:</p>
  
  <pre><code> "field": [
        1970,
        1,
        18
      ],
  </code></pre>
  
  <p>but I still want a unix timestamp when serializing like I got with <code>GregorianCalendar</code> fields: how can I achieve that? Can I avoid a custom serializer (and deserializer)?</p>
  
  <p>These are relevant for resource responses and request bodies (as in POST, PUT, etc), not for request parameters.</p>
  
  <p>The Jackson <code>ObjectMapper</code> is configured like so:</p>
  
  <pre><code>jacksonConverter.getObjectMapper().enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  jacksonConverter.getObjectMapper().disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
  </code></pre>