Spring web: @RequestBody Json for Java8 LocalTime not working

In my Spring REST web application, I am trying to get a controller working with Java8 LocalTime. I am sending this Json in a POST request

{
    "hour": "0",
    "minute": "0",
    "second": "0",
    "nano": "0"
}

and I get a HttpMessageNotReadableExceptionwith the next Jackson error

Could not read JSON: No suitable constructor found for type [simple type, class java.time.LocalTime]: can not instantiate from JSON object (need to add/enable type information?) 
at [Source: org.apache.catalina.connector.CoyoteInputStream@58cfa2a0; line: 2, column: 5]; 
nested exception is com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class java.time.LocalTime]: can not instantiate from JSON object (need to add/enable type information?) 
at [Source: org.apache.catalina.connector.CoyoteInputStream@58cfa2a0; line: 2, column: 5]

I am using spring -web-4.0.3.RELEASE with spring-boot-starter-web-1.0.2.RELEASE, jackson-databind-2.4.2 and jackson-datatype-jsr310-2.4 0.2

From what I understood, googling around, Spring should automatically register JSR-310 modules for Java8.time objects.

I found the answer to my problem, but it didn’t work for me: Spring Boot and Jackson, JSR310 in the response body

I have no configurations annotated with @EnableWebMvc and here is my only configuration class

@EnableAutoConfiguration
@ComponentScan
@EnableAspectJAutoProxy()
@Configuration
@ImportResource(value = "Beans.xml") 
public class Application extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new StringToLocalDateTime());
        registry.addConverter(new LocalDateTimeToString());
        registry.addConverter(new StringToLocalDate());
        registry.addConverter(new LocalDateToString());
        registry.addConverter(new StringToLocalTime());
        registry.addConverter(new LocalTimeToString());
    }
}

Can you guess what is wrong in my configuration?

+4
3

.

Spring Boot 1.2.0.RELEASE. Spring 4.1.3, MappingJackson2HttpMessageConverter. , https://github.com/spring-projects/spring-boot/issues/1620#issuecomment-58016018. .

Spring Boot, , , , LocalTime, :

@JsonSerialize(using = DateTimeSerializer.class)
@JsonDeserialize(using = DateTimeDeserializer.class)
private LocalTime date;
+4

Bean Spring,

@Configuration
public class JacksonConfiguration {

    @Bean
    public JSR310Module jsr310Module() {
        return new JSR310Module();
    }
}
+4

With SpringBoot 1.5, I used the following dependency and works out of the box!

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
+1
source

All Articles