Git Product home page Git Product logo

mongo-jackson-codec's Introduction

mongo-jackson-codec

Mongo Codec using Jackson (and bson4jackson) for serialization

Usage

CodecRegistry codecRegistry = CodecRegistries.fromRegistries(MongoClient.getDefaultCodecRegistry(),
                                                             CodecRegistries.fromProviders(new JacksonCodecProvider(ObjectMapperFactory.createObjectMapper())));

MongoClientOptions clientOptions = MongoClientOptions.builder()
                                                 .codecRegistry(codecRegistry)
                                                 .build();

MongoClient client = new MongoClient(new ServerAddress(), options);

MongoCollection<BlogPost> blogPosts = client.getDatabase("blog").getCollection("posts", BlogPost.class);

BlogPost blogPost1 = new BlogPost("/first_blog",
                              asList(new BlogPostComment(1, "First Comment"), new BlogPostComment(2, "Second Comment")));

BlogPost blogPost2 = new BlogPost("/second_blog",
                              asList(new BlogPostComment(2, "First Comment"), new BlogPostComment(2, "Second Comment")));

blogPosts.insertMany(asList(blogPost1, blogPost2));

List<BlogPost> allBlogPosts = blogPosts.find().into(new ArrayList<>()));

Mapping

If you want to have ObjectId represented as String, annotate your field with @Id

Dependency.

Maven

<dependency>
  <groupId>fr.javatic.mongo</groupId>
  <artifactId>mongo-jackson-codec</artifactId>
  <version>3.0.4__0.2</version>
  <scope>compile</scope>
</dependency>

Gradle

repositories {
    maven { url "http://dl.bintray.com/ylemoigne/maven" }
}

dependencies {
    compile 'fr.javatic.mongo:mongo-jackson-codec:3.0.4__0.2'
}

Changelog

0.1 Initial Release

0.2 Update to mongo 3.0.4 + test (thanks to https://github.com/mkmelin)

mongo-jackson-codec's People

Contributors

jyemin avatar ylemoigne avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.