Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing findAndRegisterModules() when initialising the ObjectMapper #70

Open
davide1995 opened this issue Apr 23, 2023 · 4 comments
Open

Comments

@davide1995
Copy link

davide1995 commented Apr 23, 2023

With RethinkDB Java Driver 2.4.4, if an OffsetDateTime is being saved, following error occurs:
java.lang.IllegalArgumentException: Java 8 date/time type java.time.OffsetDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: ch.yourpackage.YourClass["yourField"])

I state that com.fasterxml.jackson.datatype:jackson-datatype-jsr310 is already in my build.gradle file.

To avoid the above issue, as a workaround I need to include this line during RethinkDB initializer:
RethinkDB.setResultMapper(RethinkDB.getResultMapper().findAndRegisterModules());

My advice would be to modify your getResultMapper() method in the RethinkDB.java class as follows:

public synchronized static @NotNull ObjectMapper getResultMapper() {
        ObjectMapper mapper = resultMapper;
        if (mapper == null) {
            mapper = new ObjectMapper()
                .findAndRegisterModules() // This line should be the new one
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
            resultMapper = mapper;
        }
        return mapper;
    }
@srh srh transferred this issue from rethinkdb/rethinkdb Apr 24, 2023
@srh
Copy link
Contributor

srh commented Apr 24, 2023

Huh. At least going by the documentation, OffsetDateTime should be supported: https://rethinkdb.com/api/java/expr/

I wonder if this could be fixed by a change in https://github.com/rethinkdb/rethinkdb-java/blob/master/build.gradle.kts

I'm very unfamiliar with gradle, Jackson, or this driver, so maybe somebody else can chime in.

@davide1995
Copy link
Author

Is there any update on that?

@srh
Copy link
Contributor

srh commented May 23, 2023

Apparently not.

@ROMVoid95
Copy link

Auto-Registering in the current version of Jackson registers the legacy version JSR310Module. Which was depreciated in 2.5.
and replaced by JavaTimeModule

    public synchronized static @NotNull ObjectMapper getResultMapper() {
        ObjectMapper mapper = resultMapper;
        if (mapper == null) {
            mapper = new ObjectMapper()
                .registerModule(new JavaTimeModule())
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
            resultMapper = mapper;
        }
        return mapper;
    }
    ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants