I'm playing around with Spring Boot 2.0.0M2, trying to create a CLI application, not a web one. My problem is that even including
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-json'
in my build, ObjectMapper is not created by Boot because
Bean method 'jacksonObjectMapper' not loaded because @ConditionalOnClass did not find required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder'
What's the best practice when you want to have Spring Boot instance and configure Jackson but don't want to start a web server?
Overview. When using JSON format, Spring Boot will use an ObjectMapper instance to serialize responses and deserialize requests. In this tutorial, we'll take a look at the most common ways to configure the serialization and deserialization options. To learn more about Jackson, be sure to check out our Jackson tutorial.
Assuming no configuration is required, just a plain ObjectMapper will do. It's OK to be declared as static. But in environment like Spring, IMHO you should declare it as a bean.
Now Spring Boot Starters provides all those with just a single dependency. The official starters follow a naming convention spring-boot-starter-*, where * denotes application type. For example, if we want to build web including RESTful applications using Spring MVC we have to use spring-boot-starter-web dependency.
Spring Boot Starter Tomcat is the default embedded container for Spring Boot Starter Web. We cannot exclude it while using web services. We can exclude it when we want to use another embedded container. It also supports Jetty Server and Undertow Server.
You can add spring-boot-starter-json
if you want to avoid to include the full web stack (since Spring Boot v.2.0.0M4).
Why don't you just initialize it yourself.
@Bean
ObjectMapper objectMapper() {
return new ObjectMapper();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With