Search code examples
javajsonquarkus

Issue with jackson-datatype-jsr310 in Quarkus


I have a service that calls external API and converts what it gets into some Object. I tested that service and it works fine, it converts it correctly into wanted Object. The issue is that it fails when it comes to the controller and has to return the result. It fails on ZonedDateTime even though it did it successfully (I checked it in debugger). This is the error:

Java 8 date/time type java.time.ZonedDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain

I added dependency that is needed:

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.15.2</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jsr310</artifactId>
      <version>2.15.2</version>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jackson</artifactId>
      <version>3.4.1</version>
    </dependency>
...

I did include that module in my Object Mapper:

private ObjectMapper objectMapper;

public Class() {
        objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.findAndRegisterModules();
    }

This code is migrated from Spring Boot, I am not sure if there is other way to do this because the documentation is not there and community is not that large yet so I can't find any ideas online.


Solution

  • I was using RestEASY Classic instead of RestEASY Reactive Jackson. When I changed the dependency it worked.