Java compilation error: "package com.fasterxml.jackson.annotation does not exist"
Asked Answered
C

5

25

The following class is showing issue - The import com.fasterxml.jackson cannot be resolved -

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;


@JsonIgnoreProperties(ignoreUnknown=true)
public class MerchantDetailsDto {

Compilation error on running clean install -

[ERROR] COMPILATION ERROR : 

[INFO] -------------------------------------------------------------

[ERROR] /Path/to/src/main/java/com/citruspay/common/dto/merchant/MerchantDetailsDto.java:[9,40] package com.fasterxml.jackson.annotation does not exist

[ERROR] /Path/to/src/main/java/com/citruspay/common/dto/merchant/MerchantDetailsDto.java:[11,2] cannot find symbol

symbol: class JsonIgnoreProperties

The pom definition is this, which is in the pom of a project which is defined as dependency of the current project -

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

And

<jackson-core.version>2.6.1</jackson-core.version>

I checked the maven repository for this component, and it seems it does not have any dependency.

I tried changing the version to latest - 2.10.0.pr1 and tried doing maven update of the dependency project but could not find the jar downloaded inside .m2. There are two paths where the directory structure corresponding to this component is there -

.m2/fasterxml/jackson/core/jackson-annotations

.m2/repository/com/fasterxml/jackson/core/jackson-annotations

I am not sure which of these is the actual one, so I tried deleting the existing version directory from both of these, but even the same version jar did not get downloaded when I tried maven update and clean install.

Would appreciate any pointers.

Update

Output of clean install command on dependency project -

[INFO] Scanning for projects...
[INFO] 
[INFO] ------< com.project.path.to.project-dependency >------
[INFO] Building project-dependency 1.0-SNAPSHOT
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ project-dependency ---
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ citruspay-spring-dependencies ---
[INFO] Installing /Path/to/dependency/project/pom.xml to /path to/.m2/repository/com/project/path/to/dependency/1.0-SNAPSHOT/project-dependency-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.417 s
[INFO] Finished at: 2019-07-24T17:25:42+05:30
[INFO] ------------------------------------------------------------------------
Course answered 24/7, 2019 at 12:10 Comment(4)
Is there any error while downloading dependencies (since You deleted folders in .m2)? Or does it just not download it at all?Invalidism
No error. Updated with output of clean install command on dependency project.Course
if You are using intellij try to synchronize (File -> Synchronize). Not sure if similar options are available (or needed) in other IDEInvalidism
The issue resolved for me after removing the <dependencyManagement> tag in the parent project's pom. However, I have no clear idea yet about the implications of the same. Although, the jar got downloaded and I could proceed, I am getting lots of errors in compiling dependent projects like - 'dependencies.dependency.version' for com.google.guava:guava:jar is missingCourse
B
26

use

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

This will bring in the two transitive dependencies:

Biometry answered 9/6, 2020 at 14:39 Comment(0)
P
2

In my case I was missing the below Jackson XML dependency.

<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.13.4</version>
</dependency>
Pepe answered 9/9, 2022 at 14:30 Comment(0)
C
2

invalidate cache, restart and rebuild project.

File -> invalidate cache

maven -> lifecycle -> install

It should work afterwards.

Cony answered 5/1, 2023 at 2:45 Comment(0)
K
2

After moving my project from one computer to another I got the same problem.

Since I am using Json, XML and YAML, I had to add the following dependencies to the root of my pom.xml file:

<dependencies>
    <!-- Jackson - Json -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.14.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.14.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.14.2</version>
    </dependency>

    <!-- Jackson - XML -->
    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
        <version>2.14.2</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.woodstox</groupId>
        <artifactId>stax2-api</artifactId>
        <version>4.2.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.woodstox</groupId>
        <artifactId>woodstox-core</artifactId>
        <version>6.5.0</version>
    </dependency>

    <!-- Jackson - YAML -->
    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-yaml</artifactId>
        <version>2.14.2</version>
    </dependency>
    <dependency>
        <groupId>org.yaml</groupId>
        <artifactId>snakeyaml</artifactId>
        <version>2.0</version>
    </dependency>
</dependencies>

Then after a restart of the IntelliJ IDEA, everything worked like a charm again...

Kappa answered 20/4, 2023 at 16:46 Comment(0)
D
0

if your project has module, add "jackson dependency" both on parent's and child's pom.xml

Disinherit answered 2/10, 2023 at 11:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.