9

NOT A DUPLICATE -- I'm trying to follow the solutions given in Is there a jackson datatype module for JDK8 java.time? (it is the cause of this question, not a duplicate).

I added

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-modules-java8</artifactId>
    <version>2.9.5</version>
    <type>pom</type>
</dependency>

But I'm still not able to do this:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());

The JavaTimeModule class is nowhere to be found. What am I doing wrong?

Alex R
  • 11,364
  • 15
  • 100
  • 180
  • check if package added to the classpath when you execute maven you should be able to import the package – Panos K Apr 30 '18 at 22:04
  • All the answers on the page *you* linked to says to depend on `jackson-datatype-jsr310`. Don't know where you got it, but `jackson-modules-java8` isn't listed *anywhere* in the question or any of the answers. I'm closing this as a duplicate of [your own link](https://stackoverflow.com/q/21384820/5221149). Even the [documentation of the `jackson-modules-java8` module](https://github.com/FasterXML/jackson-modules-java8#usage) you're trying to depend on says that. – Andreas Apr 30 '18 at 22:18
  • 1
    To beginners with java modules (Java 9+), do not forget to add the 'requires com.fasterxml.jackson.datatype.jsr310' in module-info.java. – lubrum Oct 20 '22 at 22:21

1 Answers1

11

Use the following dependency:

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>2.9.5</version>
</dependency>

Then you'll be able to register the JavaTimeModule class. See the documentation for details.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359