Reputation: 604
I am having below class
@SpringBootApplication
public class TestApplication {
public static void main(final String[] args) {
SpringApplication.run(TestApplication.class, args);
}
@Bean
public Module jdk8Module() {
return new Jdk8Module();
}
@Bean
public Module guavaModule() {
return new GuavaModule();
}
}
Here these two beans automatically registered in jackson ObjectMapper. How it's registered this modules automatically?
Upvotes: 2
Views: 1150
Reputation: 159185
This is done by the Spring Boot JacksonAutoConfiguration
class.
As the javadoc says:
Auto configuration for Jackson. The following auto-configuration will get applied:
- an
ObjectMapper
in case none is already configured.- a
Jackson2ObjectMapperBuilder
in case none is already configured.- auto-registration for all
Module
beans with allObjectMapper
beans (including the defaulted ones).
Upvotes: 3
Reputation: 590
Any beans of type com.fasterxml.jackson.databind.Module are automatically registered with the auto-configured Jackson2ObjectMapperBuilder and are applied to any ObjectMapper instances that it creates. This provides a global mechanism for contributing custom modules when you add new features to your application. so it should be enough to define a bean and it will be automatically registered in jackson ObjectMapper.
Upvotes: 2