Home > Enterprise >  The package com.fasterxml.jackson.databind is not accessible Java (268436910)
The package com.fasterxml.jackson.databind is not accessible Java (268436910)

Time:12-04

I have recently explored handling JSON data with the org.json library and all went well. Now I started a bigger Maven project, for which I intend to use the Jackson libraries in stead. Sadly, it does not seem to work for me. I wanted to try out the ObjectMapper class, that VScode autocompleted for me, which also automatically adds the required import:

import com.fasterxml.jackson.databind.ObjectMapper;

However, I also immediately get an error on that line: "The type com.fasterxml.jackson.databind.ObjectMapper is not accessible Java (16778666)"

I have added the necessary dependencies to my pom.xml file like so:

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>13</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>13</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.14.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.14.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.14.0</version>
    </dependency>
</dependencies>

Am I missing something? Are there any other steps that I should have taken?

CodePudding user response:

This is not a Maven problem. You probably have created a package-info.java for your project and so all your dependencies ended up on the module path but your package-info.java is missing the corresponding declarations.

You have to add a line like this:

requires com.fasterxml.jackson.databind;

See also: How to fix 'Package is declared in module, but module does not read it' error in IntelliJ JavaFX?

CodePudding user response:

The only dependency needed for ObjectMapper is

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

This error occurs, because Jackson library is not included in your project's classpath. Probably your project is using the Java Platform Module System (JPMS); then log would also contain:

... declared in the "unnamed module" ... module does not read it.

If this is the case, add a requires directive to module-info.java file to specify that this module requires the jackson-databind library:

module correct.module.name {
  requires com.fasterxml.jackson.databind;
}

After adding this requires directive recompile the project again.

  • Related