Search code examples
javamavenjackson

package com.fasterxml.jackson.databind.annotation does not exist


I'm trying to do mvn clean install and I'm getting the below error. How can I resolve this, I even tried mvn clean install -U but it doesn't work at all. This is a java lib which add as a dependency for my main java project which is running in tomcat server.

package com.fasterxml.jackson.databind.annotation does not exist

My pom.xml file as below,

<properties>
    <jackson.version>2.10.0</jackson.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson</groupId>
            <artifactId>jackson-bom</artifactId>
            <version>${jackson.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- Jackson -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>${jackson.version}</version>
    </dependency>
</dependencies>

Solution

  • You also need the jackson-databind dependency.

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    

    I am not sure why you are manipulating the Jackson versions. Only necessary if you do not want to use the version specified in the springboot-starter-parent. The following is sufficient to use the spring recommended Jackson version. Note no version mentioned:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
    </dependency>
    
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    

    If you need to use another version of Jackson all you need is the following:

    <properties>
        <jackson.version>2.10.0</jackson.version>
    </properties>