Example usage for com.mongodb.client MongoCollection withDocumentClass

List of usage examples for com.mongodb.client MongoCollection withDocumentClass

Introduction

In this page you can find the example usage for com.mongodb.client MongoCollection withDocumentClass.

Prototype

<NewTDocument> MongoCollection<NewTDocument> withDocumentClass(Class<NewTDocument> clazz);

Source Link

Document

Create a new MongoCollection instance with a different default class to cast any documents returned from the database into..

Usage

From source file:org.mongojack.JacksonMongoCollection.java

License:Apache License

private JacksonMongoCollection(com.mongodb.client.MongoCollection<?> mongoCollection, ObjectMapper objectMapper,
        Class<T> valueClass, Class<?> view) {
    this.objectMapper = objectMapper == null ? DEFAULT_OBJECT_MAPPER : objectMapper;
    this.view = view;
    JacksonCodecRegistry jacksonCodecRegistry = new JacksonCodecRegistry(this.objectMapper, this.view);
    jacksonCodecRegistry.addCodecForClass(valueClass);
    this.mongoCollection = mongoCollection.withDocumentClass(valueClass)
            .withCodecRegistry(jacksonCodecRegistry);
    ;/*from w w w .j av  a2s.c  om*/
    this.valueClass = valueClass;
    this.type = this.objectMapper.constructType(valueClass);
}