# How to Resolve the Inaccessible Package com.fasterxml.jackson.databind Error in Spring Boot

> Resolve the inaccessible package com.fasterxml.jackson.databind error in Spring Boot by adding spring-boot-starter-json or starter-web dependency to your build file. Fix Jackson issues now.

- Repository: [Spring/spring-boot](https://github.com/spring-projects/spring-boot)
- Tags: how-to-guide
- Published: 2026-02-16

---

**Add the `spring-boot-starter-json` or `spring-boot-starter-web` dependency to your build file to bring the Jackson databind library onto the classpath, allowing Spring Boot's `Jackson2AutoConfiguration` to create the required `ObjectMapper` bean.**

Spring Boot relies on the **Jackson databind library** (`com.fasterxml.jackson.databind`) for JSON serialization and deserialization rather than shipping its own JSON implementation. When this library is missing from your classpath, any code importing `com.fasterxml.jackson.databind.*`—such as custom serializers or REST controllers returning POJOs—will fail with the *"package com.fasterxml.jackson.databind is not accessible"* compilation error.

## Why the Error Occurs

Spring Boot does not embed Jackson directly. Instead, it provides **auto-configuration** that activates only when the `ObjectMapper` class is detected on the classpath. This mechanism lives in the `spring-boot-jackson2` module.

### The Role of Jackson2AutoConfiguration

In [`module/spring-boot-jackson2/src/main/java/org/springframework/boot/jackson2/autoconfigure/Jackson2AutoConfiguration.java`](https://github.com/spring-projects/spring-boot/blob/main/module/spring-boot-jackson2/src/main/java/org/springframework/boot/jackson2/autoconfigure/Jackson2AutoConfiguration.java), the configuration class is annotated with `@ConditionalOnClass(ObjectMapper.class)`. This means the bean definitions inside—responsible for creating the default `ObjectMapper` and registering `JsonComponent` modules—are only processed when `com.fasterxml.jackson.databind.ObjectMapper` is available. If the JAR is missing, the configuration skips, and your application lacks the necessary JSON infrastructure, resulting in compilation errors when you try to import the package.

## Root Causes and Solutions

The inaccessible package error typically stems from one of three build configuration issues.

### Missing spring-boot-starter-json Dependency

The most common cause is omitting the starter that declares Jackson. In `starter/spring-boot-starter-json/build.gradle`, the module explicitly declares `tools.jackson.core:jackson-databind` as a dependency (line 29). Without this starter, Gradle or Maven will not transitively download the Jackson JARs.

**Fix:** Add the starter to your build file.

### Explicit Exclusion of jackson-databind

You may have deliberately excluded Jackson to use a different JSON library, or a transitive dependency conflict caused an exclusion. If `jackson-databind` is excluded via `<exclusion>` in Maven or `exclude` in Gradle, the package becomes unavailable.

**Fix:** Remove the exclusion or explicitly add `jackson-databind` back to your dependencies.

### BOM Version Misalignment

If your project does not import the **Spring Boot BOM** (`platform/spring-boot-dependencies/build.gradle`), you risk version mismatches or missing artifacts. The BOM aligns all Jackson artifact versions (`jackson-annotations`, `jackson-core`, `jackson-databind`) with the Spring Boot release.

**Fix:** Ensure you are using the Spring Boot parent POM (Maven) or the `platform` dependency (Gradle) to manage versions.

## Step-by-Step Fixes

### Maven Configuration

Add the JSON starter to your [`pom.xml`](https://github.com/spring-projects/spring-boot/blob/main/pom.xml). If you already use `spring-boot-starter-web`, you can skip this step as it transitively includes the JSON starter.

```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-json</artifactId>
</dependency>

```

Ensure your project inherits from the Spring Boot parent to get the correct Jackson versions:

```xml
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.5</version>
    <relativePath/>
</parent>

```

### Gradle Configuration

For Gradle with the Kotlin DSL:

```kotlin
implementation("org.springframework.boot:spring-boot-starter-json")

```

Or with the Groovy DSL (as used in the Spring Boot repository):

```groovy
implementation 'org.springframework.boot:spring-boot-starter-json'

```

If you prefer to include the web stack:

```groovy
implementation 'org.springframework.boot:spring-boot-starter-web'

```

Ensure you are using the Spring Boot plugin to manage the BOM:

```groovy
plugins {
    id 'org.springframework.boot' version '3.2.5'
    id 'io.spring.dependency-management' version '1.1.5'
    id 'java'
}

```

### Verifying the Fix

After updating your build file, refresh the project and check that `jackson-databind` appears in your dependency tree.

For Maven:

```bash
mvn dependency:tree | grep jackson

```

For Gradle:

```bash
./gradlew dependencies --configuration runtimeClasspath | grep jackson

```

You should see entries for `jackson-core`, `jackson-databind`, and `jackson-annotations`. Once present, the `com.fasterxml.jackson.databind` package becomes accessible, and `Jackson2AutoConfiguration` will successfully create the `ObjectMapper` bean.

## Customizing the ObjectMapper After Resolution

Once the classpath issue is resolved, Spring Boot's `Jackson2AutoConfiguration` (located in [`module/spring-boot-jackson2/src/main/java/org/springframework/boot/jackson2/autoconfigure/Jackson2AutoConfiguration.java`](https://github.com/spring-projects/spring-boot/blob/main/module/spring-boot-jackson2/src/main/java/org/springframework/boot/jackson2/autoconfigure/Jackson2AutoConfiguration.java)) automatically registers an `ObjectMapper` bean. You can customize this bean using the `Jackson2ObjectMapperBuilder` provided by the same module.

```java
@Configuration
public class JacksonConfig {

    @Bean
    @Primary
    public ObjectMapper customObjectMapper(Jackson2ObjectMapperBuilder builder) {
        return builder
                .indentOutput(true)                 // pretty-print JSON
                .propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
                .build();
    }
}

```

The `JsonComponentModule` (found in [`module/spring-boot-jackson2/src/main/java/org/springframework/boot/jackson2/JsonComponentModule.java`](https://github.com/spring-projects/spring-boot/blob/main/module/spring-boot-jackson2/src/main/java/org/springframework/boot/jackson2/JsonComponentModule.java)) also scans for `@JsonComponent` annotated classes and registers them automatically with the `ObjectMapper`.

## Summary

- **Spring Boot delegates JSON processing to Jackson.** The framework does not include its own JSON library; it relies on `com.fasterxml.jackson.databind` via the `spring-boot-starter-json` starter.
- **The error indicates a missing classpath dependency.** When `jackson-databind` is absent, imports fail and `Jackson2AutoConfiguration` cannot create the `ObjectMapper` bean.
- **Add the correct starter to fix it.** Include `spring-boot-starter-json` (or `spring-boot-starter-web`) in your Maven or Gradle build and ensure you are using the Spring Boot BOM for version alignment.
- **Verify with dependency commands.** Use `mvn dependency:tree` or `./gradlew dependencies` to confirm `jackson-databind` is present before rebuilding.

## Frequently Asked Questions

### What is the com.fasterxml.jackson.databind package?

The `com.fasterxml.jackson.databind` package is the core API of the **Jackson databind library**, which provides the `ObjectMapper` class and related utilities for converting Java objects to JSON and vice versa. Spring Boot uses this library as its default JSON processing engine through the `Jackson2AutoConfiguration` class.

### Why does Spring Boot need Jackson on the classpath?

Spring Boot's auto-configuration mechanism, specifically `Jackson2AutoConfiguration` in the `spring-boot-jackson2` module, is conditional on the presence of `ObjectMapper.class`. This design allows Spring Boot to provide a fully configured `ObjectMapper` bean, HTTP message converters, and support for `@JsonComponent` classes only when the Jackson library is available, keeping the framework modular.

### Can I use a different JSON library instead of Jackson?

Yes, but you must provide the necessary configuration yourself. If you exclude `jackson-databind` and use an alternative like **Gson** or **JSON-B**, you will need to define your own `HttpMessageConverter` beans and disable the Jackson auto-configuration. However, the `com.fasterxml.jackson.databind` error specifically indicates that your code is trying to import Jackson classes, so you must either add Jackson or refactor your code to use the alternative library's APIs.

### How do I check if Jackson is correctly included in my build?

Run your build tool's dependency tree command and filter for Jackson. For Maven, execute `mvn dependency:tree | grep jackson` and look for `jackson-databind`, `jackson-core`, and `jackson-annotations`. For Gradle, run `./gradlew dependencies --configuration runtimeClasspath | grep jackson`. If these artifacts appear with versions aligned to your Spring Boot release (managed by the BOM), the package will be accessible at compile time.