Spring Boot issues serializing java.time.LocalDateTime with Jackson to return ISO-8601 JSON timestamps?
<p>I'm working on converting some models in a spring-boot REST API app to use java 8's <code>java.time.LocalDateTime</code> instead of joda's <code>DateTime</code>. I want the timestamps returned from API call to adhere to the <code>ISO_8601</code> format. Motivation is to be forward compatible with Java 8's time (<a href="https://stackoverflow.com/a/24635657/187907">more here</a>).</p>

<p>The part that's proving difficult is when it comes to serialize an object containing <code>LocalDateTime</code> to JSON. </p>

<p>For example, I have the following entity:</p>

<pre><code>// ... misc imports

import java.time.LocalDateTime;
import java.time.ZoneOffset;

@Data 
@Entity
@Table(name = "users")
public class User {

    @Id @Column
    private String id;

    @Column
    private String name;

    @Column
    private String email;

    @Column
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "UTC")
    private java.time.LocalDateTime createdAt;

    public User(String name, String email) {
        this.id = Utils.generateUUID();
        this.createdAt = LocalDateTime.now(ZoneOffset.UTC);
    }
}
</code></pre>

<p>I have also set my <code>application.properties</code> to turn off the dates as timestamp jackson feature:</p>

<pre><code>spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false
</code></pre>

<p>My maven deps:</p>

<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;version&gt;1.3.6.RELEASE&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.8.1&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
     &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
     &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
     &lt;version&gt;5.0.1.Final&lt;/version&gt;
 &lt;/dependency&gt;
</code></pre>

<p>Finally, I try to retrieve the JSON representation via controller:</p>

<pre><code>@RequestMapping("/users")
@RestController
public class UserController {

    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping(
        value = "/{id}",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    public User getUser(@PathVariable("id") String id) {
        return userService.findById(id);
    }
}
</code></pre>

<p>When I actually make a call to this endpoint, I get the following exception:</p>

<pre><code>java.lang.NoSuchMethodError: 
com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase.findFormatOverrides(Lcom/fasterxml/jackson/databind/SerializerProvider;Lcom/fasterxml/jackson/databind/BeanProperty;Ljava/lang/Class;)Lcom/fasterxml/jackson/annotation/JsonFormat$Value;
</code></pre>

<p>Alternately I also configured the app's <code>ObjectMapper</code> in the configuration class:</p>

<pre><code>@Configuration
public class ServiceConfiguration {

    @Bean
    public ObjectMapper getJacksonObjectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.configure(
            com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
            false
        );
        return objectMapper;
    }
}
</code></pre>

<p>Any leads will be greatly appreciated. </p>

<hr>

<h2>UPDATE:</h2>

<p>Turns out it was a version mismatch between Spring Boot's Jackson version and the one I had in my <code>pom.xml</code>. As Miloš and Andy proposed, once I've set the correct version and run the app with <code>spring.jackson.serialization.write_dates_as_timestamps=true</code>, the issue was resolved, without needing to configure the <code>ObjectMapper</code> or adding annotations on my <code>LocalDateTime</code> model fields.</p>

<pre><code>    ...
    &lt;dependencyManagement&gt;
        &lt;dependencies&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-dependencies&lt;/artifactId&gt;
                &lt;version&gt;1.3.6.RELEASE&lt;/version&gt;
                &lt;type&gt;pom&lt;/type&gt;
                &lt;scope&gt;import&lt;/scope&gt;
            &lt;/dependency&gt;
        &lt;/dependencies&gt;
    &lt;/dependencyManagement&gt;

    &lt;dependencies&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
            &lt;version&gt;1.3.6.RELEASE&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;org.hibernate&lt;/groupId&gt;
            &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
        &lt;/dependency&gt;

    &lt;/dependencies&gt;
</code></pre>