Skip to content

emmilydev/mongo-gson-codec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongo-gson-codec


This is a lightweight Mongo codec that uses Gson for serialization.

Usage:

You just need to add the GsonCodecProvider to your CodecRegistry!

public class Example {
  
  public void init() {
    CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
        CodecRegistries.fromCodecs(
            MongoClientSettings.getDefaultCodecRegistry() // or your codec registry
        ),
        CodecRegistries.fromProviders(
            new GsonCodecProvider(
                new Gson(),
                new BsonDocumentCodec()
            )
        )
    );
    MongoClient mongoClient = MongoClients.create();
    MongoDatabase mongoDatabase = mongoClient.getDatabase(
        "example"
    ).withCodecRegistry(codecRegistry);
    MongoCollection<Pojo> pojoMongoCollection = mongoDatabase.getCollection(
        "pojos",
        Pojo.class
    );
    // ...
  }
}

About

A lightweight Mongo codec that uses Gson.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages