title: Java 8 date time types serialized as object with Spring Boot
body: <p>I have an entity with fields of Java 8 date time types. The issue is that these fields are serialized as object. I added the <code>jackson-datatype-jsr310</code> dependency, so Spring Boot 1.5.7 would auto configure the <code>JavaTimeModule</code> that handles Java 8 date time types. It seems that the module is not registered (I put a breakpoint in JavaTimeModule constructor). I know I don't need a custom <code>ObjectMapper</code>. I spent hours reading about that issue and the solution is always to add the <code>jackson-datatype-jsr310</code> dependency but it does not work in my case.</p>
  
  <p>The entity:</p>
  
  <pre><code>@Entity
  public class DateTimeEntity {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      private LocalDate localDate;
  
      private LocalDateTime localDateTime;
  
      private Instant instant;
  
      private OffsetDateTime offsetDateTime;
  
      private ZonedDateTime zonedDateTime;
  
  }
  </code></pre>
  
  <p>The RestController method:</p>
  
  <pre><code>@GetMapping("/datetimes/{id}")
  public ResponseEntity&lt;DateTimeEntity&gt; getById(@PathVariable Long id) {
      DateTimeEntity dateTimeEntity = dateTimeRepository.findOne(id);
      return new ResponseEntity&lt;DateTimeEntity&gt;(dateTimeEntity, HttpStatus.OK);
  
  }
  </code></pre>
  
  <p>The JSON object returned:</p>
  
  <pre><code>    {
      "id": 1,
      "localDate": null,
      "localDateTime": null,
      "instant": {
          "epochSecond": 1508772600,
          "nano": 0
      },
      "offsetDateTime": {
          "offset": {
              "totalSeconds": 0,
              "id": "Z",
              "rules": {
                  "fixedOffset": true,
                  "transitionRules": [],
                  "transitions": []
              }
          },
          "dayOfMonth": 23,
          "dayOfWeek": "MONDAY",
          "dayOfYear": 296,
          "month": "OCTOBER",
          "monthValue": 10,
          "year": 2017,
          "hour": 15,
          "minute": 30,
          "nano": 0,
          "second": 0
      },
      "zonedDateTime": {
          "offset": {
              "totalSeconds": 0,
              "id": "Z",
              "rules": {
                  "fixedOffset": true,
                  "transitionRules": [],
                  "transitions": []
              }
          },
          "zone": {
              "totalSeconds": 0,
              "id": "Z",
              "rules": {
                  "fixedOffset": true,
                  "transitionRules": [],
                  "transitions": []
              }
          },
          "dayOfMonth": 23,
          "dayOfWeek": "MONDAY",
          "dayOfYear": 296,
          "month": "OCTOBER",
          "monthValue": 10,
          "year": 2017,
          "hour": 15,
          "minute": 30,
          "nano": 0,
          "second": 0,
          "chronology": {
              "id": "ISO",
              "calendarType": "iso8601"
          }
      }
  }
  </code></pre>
  
  <p>The POM file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;framework-demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.7.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;mockito.version&gt;2.11.0&lt;/mockito.version&gt;
          &lt;org.mapstruct.version&gt;1.2.0.Final&lt;/org.mapstruct.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;
              &lt;artifactId&gt;mapstruct-jdk8&lt;/artifactId&gt;
              &lt;version&gt;${org.mapstruct.version}&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;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&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;${jackson.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.5.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${java.version}&lt;/source&gt;
                      &lt;target&gt;${java.version}&lt;/target&gt;
                      &lt;annotationProcessorPaths&gt;
                          &lt;path&gt;
                              &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;
                              &lt;artifactId&gt;mapstruct-processor&lt;/artifactId&gt;
                              &lt;version&gt;${org.mapstruct.version}&lt;/version&gt;
                          &lt;/path&gt;
                      &lt;/annotationProcessorPaths&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.asciidoctor&lt;/groupId&gt;
                  &lt;artifactId&gt;asciidoctor-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.5.5&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;output-html&lt;/id&gt;
                          &lt;phase&gt;generate-resources&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;process-asciidoc&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;backend&gt;html&lt;/backend&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>