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?
2
Answers
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:
See also: How to fix 'Package is declared in module, but module does not read it' error in IntelliJ JavaFX?
The only dependency needed for
ObjectMapper
isThis 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:
If this is the case, add a
requires
directive tomodule-info.java
file to specify that this module requires the jackson-databind library:After adding this
requires
directive recompile the project again.