Thanks a lot, I finally made it. The example provided in the README[1] is
only valid for the sync driver. To use mongo-jackson-codec with the async
one you can not just call MongoClient.getDefaultCodecRegistry() or create
a new MongoClient instance, as MongoClient is an interface instead of a
class in the async driver, and the only implementation is the
MongoClientImpl class, which is not public. You have to use MongoClients
factory and set up the CodecRegistry trough a MongoClientSettings
instance. This is how my database access module looks like (a lot of code
just copied from the MongoClients and MongoClientImpl classes):
-----------------------------------------------------------
ConnectionString connectionString = new ConnectionString(
configuration.getString("mongodb.uri", "mongodb://
127.0.0.1:27017/test")
);
CodecRegistry defaultCodecRegistry = CodecRegistries
.fromProviders(Arrays.asList(new CodecProvider[]{
new ValueCodecProvider(),
new DocumentCodecProvider(),
new BsonValueCodecProvider()
}));
CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
defaultCodecRegistry, CodecRegistries.fromProviders(
new ObjectCodecProvider(
ObjectMapperFactory.createObjectMapper()
)
)
);
MongoClientSettings clientSettings = MongoClientSettings.builder()
.clusterSettings(
ClusterSettings.builder()
.applyConnectionString(connectionString)
.build()
)
.connectionPoolSettings(
ConnectionPoolSettings.builder()
.applyConnectionString(connectionString)
.build()
)
.serverSettings(ServerSettings.builder().build())
.credentialList(connectionString.getCredentialList())
.sslSettings(SslSettings.builder()
.applyConnectionString(connectionString).build()
)
.socketSettings(SocketSettings.builder()
.applyConnectionString(connectionString)
.build()
)
.codecRegistry(codecRegistry)
.build();
MongoClient mongoClient = MongoClients.create(clientSettings);
MongoDatabase database = mongoClient.getDatabase(
connectionString.getDatabase()
);
-------------------------------------------------------------
Maybe there is a simpler way of doing this, maybe with a more recent
version of the driver.
[1]
https://github.com/ylemoigne/mongo-jackson-codec/blob/master/README.md
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
>
https://groups.google.com/d/msgid/play-framework/CAO2h8AxdOvzXTbePf%3DpUgPc-StNf8sFVBzB_nc-KAKH_LNLWTA%40mail.gmail.com.