After moving to Spring Boot 4, an ObjectMapper can no longer be autowired
Your error
Parameter 0 of constructor in com.example.OrderService required a bean of type 'com.fasterxml.jackson.databind.ObjectMapper' that could not be found.1 more line it can showFix it fast
Most common cause, 1 of 3The code asks for the Jackson 2 ObjectMapper, but Boot 4 builds a Jackson 3 JsonMapper
Change the imports and inject JsonMapper.
import tools.jackson.databind.json.JsonMapper;
@Service
public class OrderService {
private final JsonMapper jsonMapper;
public OrderService(JsonMapper jsonMapper) {
this.jsonMapper = jsonMapper;
}
public String toJson(Order order) {
return jsonMapper.writeValueAsString(order);
}
}Short answer
Spring Boot 4 auto-configures Jackson 3, so the bean it creates is tools.jackson.databind.json.JsonMapper. Code that injects com.fasterxml.jackson.databind.ObjectMapper (Jackson 2) finds no bean and startup fails with required a bean of type that could not be found. Inject JsonMapper, or add the deprecated spring-boot-jackson2 module as a stop-gap. Applies to Spring Boot 4.0 to 4.2.
Which cause do you have?
Look at the package in the error and check which Jackson modules Boot put on the classpath. com.fasterxml.jackson.databind with spring-boot-jackson present means cause 1 or 2. No spring-boot-jackson at all, or the same error for tools.jackson.databind.json.JsonMapper, means cause 3.
./mvnw dependency:tree '-Dincludes=org.springframework.boot:spring-boot-jackson*'
# Gradle
./gradlew dependencies --configuration runtimeClasspath | grep spring-boot-jacksonThen find the line you see in this list and open its fix:
- 1The code asks for the Jackson 2 ObjectMapper, but Boot 4 builds a Jackson 3 JsonMapper
The missing type in the message is com.fasterxml.jackson.databind.ObjectMapper and the class imports it - 2Part of the app or a library must stay on Jackson 2 for now
Moving every import to tools.jackson is not possible yet, for example a library API takes a com.fasterxml ObjectMapper - 3No Jackson auto-configuration is on the classpath at all
dependency:tree prints no spring-boot-jackson, and injecting JsonMapper fails the same way
What does the error look like?
Parameter 0 of constructor in com.example.OrderService required a bean of type 'com.fasterxml.jackson.databind.ObjectMapper' that could not be found.Field objectMapper in com.example.OrderService required a bean of type 'com.fasterxml.jackson.databind.ObjectMapper' that could not be found.
Cause 1 of 3
The code asks for the Jackson 2 ObjectMapper, but Boot 4 builds a Jackson 3 JsonMapper
You seeThe missing type in the message is com.fasterxml.jackson.databind.ObjectMapper and the class imports it
Check
Spring Boot 4 uses Jackson 3 as its preferred JSON library, and Jackson 3 moved from com.fasterxml.jackson to the tools.jackson packages. When Jackson is on the classpath, Boot creates a JsonMapper bean of the new type. A field or constructor typed with the old com.fasterxml class matches no bean, so the context stops at startup.
grep -rn "import com.fasterxml.jackson.databind" src/main/javaFix
Change the imports and inject JsonMapper. Jackson 3 exceptions extend RuntimeException, so old catch blocks for checked Jackson 2 exceptions need a look. If you defined your own ObjectMapper bean to replace Boot's, define a JsonMapper bean now; an ObjectMapper bean no longer replaces the auto-configured one. Annotations such as @JsonProperty keep the com.fasterxml.jackson.annotation package.
import tools.jackson.databind.json.JsonMapper;
@Service
public class OrderService {
private final JsonMapper jsonMapper;
public OrderService(JsonMapper jsonMapper) {
this.jsonMapper = jsonMapper;
}
public String toJson(Order order) {
return jsonMapper.writeValueAsString(order);
}
}Verify
The application starts, and a controller or test that serializes an object returns JSON.
./mvnw spring-boot:runConfirmed by github.com
Cause 2 of 3
Part of the app or a library must stay on Jackson 2 for now
You seeMoving every import to tools.jackson is not possible yet, for example a library API takes a com.fasterxml ObjectMapper
Check
Jackson 2 still has dependency management in Boot 4, but its auto-configuration lives in a separate, deprecated module. Only when spring-boot-jackson2 is on the classpath does Boot create a Jackson 2 ObjectMapper bean, configured with spring.jackson2.* properties.
./mvnw dependency:tree -Dincludes=org.springframework.boot:spring-boot-jackson2Fix
Add spring-boot-jackson2 as a short-term bridge and plan the move to Jackson 3, since the module will be removed in a later 4.x release. Customize that mapper with Jackson2ObjectMapperBuilderCustomizer beans and spring.jackson2.* properties.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-jackson2</artifactId>
</dependency>
// Gradle
implementation("org.springframework.boot:spring-boot-jackson2")Verify
The context starts and the Jackson 2 ObjectMapper is injected next to Boot's JsonMapper.
./mvnw testConfirmed by docs.spring.io
Cause 3 of 3
No Jackson auto-configuration is on the classpath at all
You seedependency:tree prints no spring-boot-jackson, and injecting JsonMapper fails the same way
Check
Spring Boot 4 split its auto-configuration into modules with matching starters. A project built only on the core spring-boot-starter, such as a batch or command-line app, does not pull in spring-boot-jackson, so no JSON mapper bean is created for either Jackson version.
./mvnw dependency:tree -Dincludes=org.springframework.bootFix
Add the Jackson starter. It brings spring-boot-jackson, which auto-configures the JsonMapper. While migrating, spring-boot-starter-classic gives you a classpath with all the infrastructure again, so you can fix imports first and trim starters later.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jackson</artifactId>
</dependency>Verify
dependency:tree now lists spring-boot-jackson and the JsonMapper injects.
./mvnw dependency:tree -Dincludes=org.springframework.boot:spring-boot-jacksonConfirmed by github.com
How do I stop it coming back?
- Before the Boot 4 upgrade, grep for com.fasterxml.jackson.databind imports and list each one with its Jackson 3 replacement in the upgrade ticket.
- Add a @SpringBootTest that loads the full context in CI, so a missing bean fails the build instead of the first deploy.
- If you add spring-boot-jackson2, open a follow-up task to remove it, because the module is deprecated and its removal is announced.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Dispatch Pro.