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?
Advertisement
Answer
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.