Search code examples
springspring-mvcspring-bootjacksonjackson-databind

How can I get an ObjectMapper instance in Spring Boot without inheriting from spring-boot-starter-web?


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?


Solution

  • 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).