Search in sources :

Example 6 with UuidCodec

use of org.bson.codecs.UuidCodec in project immutables by immutables.

the class JacksonRepoTest method setUp.

@Before
public void setUp() throws Exception {
    final MongoDatabase database = context.database();
    this.collection = database.getCollection("jackson").withDocumentClass(BsonDocument.class);
    // for our local serializers of Date and ObjectId
    SimpleModule module = new SimpleModule();
    module.addDeserializer(Date.class, new DateDeserializer());
    module.addSerializer(new DateSerializer());
    module.addDeserializer(ObjectId.class, new ObjectIdDeserializer());
    module.addSerializer(new ObjectIdSerializer());
    UuidCodec uuidCodec = new UuidCodec(UuidRepresentation.JAVA_LEGACY);
    module.addDeserializer(UUID.class, new UUIDDeserializer(uuidCodec));
    module.addSerializer(UUID.class, new UUIDSerializer(uuidCodec));
    ObjectMapper mapper = new ObjectMapper().registerModule(JacksonCodecs.module(MongoClientSettings.getDefaultCodecRegistry())).registerModule(new GuavaModule()).registerModule(module);
    RepositorySetup setup = RepositorySetup.builder().database(database).codecRegistry(JacksonCodecs.registryFromMapper(mapper)).executor(MoreExecutors.newDirectExecutorService()).build();
    this.repository = new JacksonRepository(setup);
}
Also used : UuidCodec(org.bson.codecs.UuidCodec) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) BsonDocument(org.bson.BsonDocument) RepositorySetup(org.immutables.mongo.repository.RepositorySetup) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MongoDatabase(com.mongodb.client.MongoDatabase) Before(org.junit.Before)

Example 7 with UuidCodec

use of org.bson.codecs.UuidCodec in project mongo-java-driver by mongodb.

the class AbstractExplicitUuidCodecUuidRepresentationTest method data.

@Parameterized.Parameters(name = "{0}/{1}/{2}")
public static Collection<Object[]> data() {
    UUID uuid = UUID.fromString("00112233-4455-6677-8899-aabbccddeeff");
    byte[] standardEncodedValue = Hex.decode("00112233445566778899AABBCCDDEEFF");
    List<Object[]> data = new ArrayList<Object[]>();
    data.add(new Object[] { JAVA_LEGACY, PYTHON_LEGACY, UUID_STANDARD, new UuidCodec(STANDARD), uuid, standardEncodedValue, standardEncodedValue });
    data.add(new Object[] { STANDARD, C_SHARP_LEGACY, UUID_LEGACY, new UuidCodec(UuidRepresentation.C_SHARP_LEGACY), uuid, Hex.decode("33221100554477668899AABBCCDDEEFF"), standardEncodedValue });
    data.add(new Object[] { STANDARD, JAVA_LEGACY, UUID_LEGACY, new UuidCodec(JAVA_LEGACY), uuid, Hex.decode("7766554433221100FFEEDDCCBBAA9988"), standardEncodedValue });
    data.add(new Object[] { STANDARD, PYTHON_LEGACY, UUID_LEGACY, new UuidCodec(PYTHON_LEGACY), uuid, standardEncodedValue, standardEncodedValue });
    return data;
}
Also used : UuidCodec(org.bson.codecs.UuidCodec) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) UUID(java.util.UUID)

Aggregations

UuidCodec (org.bson.codecs.UuidCodec)7 BsonDocument (org.bson.BsonDocument)4 Before (org.junit.Before)3 AutoEncryptionSettings (com.mongodb.AutoEncryptionSettings)2 ClientEncryptionSettings (com.mongodb.ClientEncryptionSettings)2 MongoClientSettings (com.mongodb.MongoClientSettings)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BsonString (org.bson.BsonString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 Fixture.getMongoClientSettings (com.mongodb.client.Fixture.getMongoClientSettings)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 Fixture.getMongoClientBuilderFromConnectionString (com.mongodb.reactivestreams.client.Fixture.getMongoClientBuilderFromConnectionString)1 Fixture.getMongoClientSettings (com.mongodb.reactivestreams.client.Fixture.getMongoClientSettings)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1