Skip to content

Missing findAndRegisterModules() when initialising the ObjectMapper #70

@davide1995

Description

@davide1995

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions