Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dorilahav.elusive.data;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.mongodb.client.MongoCollection;
- import com.mongodb.client.MongoDatabase;
- import lombok.experimental.Delegate;
- import org.mongojack.JacksonCodecRegistry;
- import org.mongojack.internal.MongoJackModule;
- public class Collection<T> {
- private final Class<T>
- clazz;
- @Delegate
- protected MongoCollection<T>
- collection;
- protected JacksonCodecRegistry
- jacksonCodecRegistry;
- public Collection(MongoDatabase database, ObjectMapper mapper, Class<T> type, String collectionName) {
- this.clazz = type;
- jacksonCodecRegistry = new JacksonCodecRegistry(mapper);
- jacksonCodecRegistry.addCodecForClass(clazz);
- this.collection = database.getCollection(collectionName).withDocumentClass(clazz).withCodecRegistry(jacksonCodecRegistry);
- }
- public Collection(MongoDatabase database, Class<T> type, String collectionName) {
- this(database, MongoJackModule.configure(new ObjectMapper()), type, collectionName);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement