I want to save to mongodb an org.bson.Document containing an OffsetDateTime instance with the OffsetDateTime saved as a DATE. It is currently saved as an Object.
I'm using my own custom MongoDatabaseFactory.
This is my test data. I've created a org.bson.Document. Appended to Document these types: java.time.OffsetDateTime, java.time.Instant, and java.util.Date.
Saved to monogdb via a MongoTemplate instance. Both Instant and Date are saved as a DATE in mongo. However OffsetDateTime is being saved as an object. I want it to save as a DATE.
I've searched google, found many questions/answers and sites stating to use CustomConverters.
43544908/usage-of-offsetdatetime-with-spring-boot-and-mongodb-results-in-mappingexception
41127665/zoneddatetime-with-mongodb/
27091418/store-java-8-instant-as-bson-date-using-springdata-mongodb
I've created two converters. OffsetDateTime -> Date and Date -> OffsetDateTime. Annotated with @WritingConverter and @ReadingConverter. Instantiated MongoCustomConversions, added my converters, set conversions on MappingMongoConverter, and passed to MongoTemplate's constructor.
I've tried many permutations setting the conversions on the MongoTemplate. None work. I've debugged this in eclipse but haven't found where the Document is being converted.
Here's what I see in mongodb. Snapshot of mongodb record Any help is appreciated.