
Jackson is the default JSON library in Spring Boot, so it’s automatically configured when you use Spring Boot’s web starter. However, you can customize its behavior as needed. Here’s how you can configure Jackson in Spring Boot:
1. Customize with application.properties
or application.yml
Spring Boot provides some Jackson configurations out of the box.
For example, in application.properties
:
spring.jackson.default-property-inclusion=non_null
spring.jackson.date-format=yyyy-MM-ddTHH:mm:ss
spring.jackson.deserialization.fail-on-unknown-properties=false
spring.jackson.property-naming-strategy=SNAKE_CASE
@Configuration
public class JacksonConfiguration {
/**
* Support for Java date and time API.
* @return the corresponding Jackson module.
*/
@Bean
public JavaTimeModule javaTimeModule() {
return new JavaTimeModule();
}
@Bean
public Jdk8Module jdk8TimeModule() {
return new Jdk8Module();
}
/*
* Support for Hibernate types in Jackson.
*/
@Bean
public Hibernate6Module hibernate6Module() {
return new
Hibernate6Module().configure(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS, true);
}
}