Registering a codec for ReactiveMongoClient Spring Boot 2

71 views
Skip to first unread message

Gintas

unread,
Apr 16, 2018, 6:20:43 PM4/16/18
to mongodb-user
Hi,

What is the process to register a codec for a ReactiveMongoClient
I use the following snippet to add the OffsetDateTimeStringCodec codec that handles OffsetDateTime type: 

public class MongoConfig extends AbstractReactiveMongoConfiguration {

   
@Override
    public MongoClient reactiveMongoClient() {
       
CodecRegistry codecRegistry = CodecRegistries.
               
fromRegistries(
                       
CodecRegistries.fromCodecs(new OffsetDateTimeStringCodec()),
                       
MongoClients.getDefaultCodecRegistry()
               
);
       
ClusterSettings cs = ClusterSettings.builder().hosts(Arrays.asList(new ServerAddress("localhost"))).build();
       
MongoClientSettings mcs = MongoClientSettings.builder()
               
.codecRegistry(codecRegistry)
               
.clusterSettings(cs)
               
.build();
       
return MongoClients.create(mcs);
   
}

   
...
}

I can add documents to the database, but instead of OffsetDateTime I see that the persisted object is identified as Object
Am I missing something?

Thanks,
Gintas
Reply all
Reply to author
Forward
0 new messages