From 74f8b118771fd226a5a15a9e89612c8a3ae93b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Mon, 2 Oct 2023 10:41:41 +0200 Subject: [PATCH] Allow configuring MongoDB client UUID representation --- .../io/quarkus/mongodb/runtime/MongoClientConfig.java | 8 ++++++++ .../java/io/quarkus/mongodb/runtime/MongoClients.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClientConfig.java b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClientConfig.java index 8c631bff5bb38..8324c19f8fd0f 100644 --- a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClientConfig.java +++ b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClientConfig.java @@ -5,6 +5,8 @@ import java.util.Optional; import java.util.OptionalInt; +import org.bson.UuidRepresentation; + import io.quarkus.runtime.annotations.ConfigDocSection; import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigItem; @@ -197,4 +199,10 @@ public class MongoClientConfig { @ConfigItem(name = "health.database", defaultValue = "admin") public String healthDatabase; + /** + * Configures the UUID representation to use when encoding instances of {@link java.util.UUID} + * and when decoding BSON binary values with subtype of 3. + */ + @ConfigItem + public Optional uuidRepresentation; } diff --git a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClients.java b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClients.java index e4e6d68d0dcc1..0c948f3c134ca 100644 --- a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClients.java +++ b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClients.java @@ -322,6 +322,10 @@ private MongoClientSettings createMongoConfiguration(MongoClientConfig config) { settings.readConcern(new ReadConcern(ReadConcernLevel.fromString(config.readConcern.get()))); } + if (config.uuidRepresentation.isPresent()) { + settings.uuidRepresentation(config.uuidRepresentation.get()); + } + return settings.build(); }