Skip to content

Find using Java 8 time on collection fails with BsonSerializationExecption #10

@golf1052

Description

@golf1052

I'm trying to do a find on a collection using a OffsetDateTime as one of the find parameters. For example
collection.find(and(eq("config_key", "foo"), lt("started_at", OffsetDateTime.now()))).first(); returns the exception below. I am registering the JavaTimeBsonModule correctly before connecting to the database as I am able to serialize classes containing OffsetDateTimes just fine. This example also does not work with ZonedDateTime and Instant.

2016-06-20T20:16:22.009953849Z Exception in thread "main" org.bson.BsonSerializationException: Detected unknown BSON type "\x55" for fieldname "�". Are you using the latest driver version?
2016-06-20T20:16:22.012424329Z  at org.bson.BsonBinaryReader.readBsonType(BsonBinaryReader.java:94)
2016-06-20T20:16:22.013202845Z  at org.bson.AbstractBsonWriter.pipeDocument(AbstractBsonWriter.java:698)
2016-06-20T20:16:22.014603469Z  at org.bson.AbstractBsonWriter.pipe(AbstractBsonWriter.java:692)
2016-06-20T20:16:22.015978394Z  at org.bson.codecs.RawBsonDocumentCodec.encode(RawBsonDocumentCodec.java:49)
2016-06-20T20:16:22.022486832Z  at org.bson.codecs.RawBsonDocumentCodec.encode(RawBsonDocumentCodec.java:37)Listening for transport dt_socket at address: 33333
2016-06-20T20:16:22.022536944Z 
2016-06-20T20:16:22.025803344Z  at fr.javatic.mongo.jacksonCodec.JacksonCodec.encode(JacksonCodec.java:58)
2016-06-20T20:16:22.025845758Z  at com.mongodb.client.model.BuildersHelper.encodeValue(BuildersHelper.java:35)
2016-06-20T20:16:22.025851109Z  at com.mongodb.client.model.Filters$OperatorFilter.toBsonDocument(Filters.java:878)
2016-06-20T20:16:22.025856020Z  at com.mongodb.FindIterableImpl.createQueryOperation(FindIterableImpl.java:172)
2016-06-20T20:16:22.025859971Z  at com.mongodb.FindIterableImpl.execute(FindIterableImpl.java:167)
2016-06-20T20:16:22.025863329Z  at com.mongodb.FindIterableImpl.first(FindIterableImpl.java:148)

There is a workaround where I convert the OffsetDateTime to a Java 7 date before doing the find. collection.find(and(eq("config_key", "foo"), lt("started_at", Date.from(OffsetDateTime.now().toInstant())))).first();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions