/** * Creates a {@code CodecRegistry} from the provided list of {@code Codec} instances. * * <p>This registry can then be used alongside other registries. Typically used when adding extra codecs to existing codecs with the * {@link #fromRegistries(CodecRegistry...)} )} helper.</p> * * @param codecs the {@code Codec} to create a registry for * @return a {@code CodecRegistry} for the given list of {@code Codec} instances. */ public static CodecRegistry fromCodecs(final Codec<?>... codecs) { return fromCodecs(asList(codecs)); }
PojoCodecImpl(final ClassModel<T> classModel, final CodecRegistry registry, final PropertyCodecRegistry propertyCodecRegistry, final DiscriminatorLookup discriminatorLookup, final ConcurrentMap<ClassModel<?>, Codec<?>> codecCache, final boolean specialized) { this.classModel = classModel; this.registry = fromRegistries(fromCodecs(this), registry); this.discriminatorLookup = discriminatorLookup; this.codecCache = codecCache; this.propertyCodecRegistry = propertyCodecRegistry; this.specialized = specialized; specialize(); }
PojoCodecImpl(final ClassModel<T> classModel, final CodecRegistry codecRegistry, final List<PropertyCodecProvider> propertyCodecProviders, final DiscriminatorLookup discriminatorLookup) { this.classModel = classModel; this.registry = fromRegistries(fromCodecs(this), codecRegistry); this.discriminatorLookup = discriminatorLookup; this.codecCache = new ConcurrentHashMap<ClassModel<?>, Codec<?>>(); this.propertyCodecRegistry = new PropertyCodecRegistryImpl(this, registry, propertyCodecProviders); this.specialized = shouldSpecialize(classModel); specialize(); }
@Bean public CodecRegistry registry(Codec[] codecs) { return CodecRegistries.fromRegistries(MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromCodecs(codecs)); }
protected I configure() { I datastore = getDatastore(); // codecs List<CodecRegistry> registries = new LinkedList<>(); if (!codecs.isEmpty()) { registries.add(CodecRegistries.fromCodecs(codecs)); } if (!codecProviders.isEmpty()) { registries.add(CodecRegistries.fromProviders(codecProviders)); } if (!registries.isEmpty()) { datastore.setAdditionalCodecRegistry(CodecRegistries.fromRegistries(registries)); } // init datastore.initialize(); return datastore; }
public <T> void addCodecForClass(Class<T> clazz) { JacksonEncoder<T> encoder = new JacksonEncoder<>(clazz, view, objectMapper); JacksonDecoder<T> decoder = new JacksonDecoder<>(clazz, view, objectMapper); JacksonCodec<T> jacksonCodec = new JacksonCodec<T>(encoder, decoder); codecRegistry = CodecRegistries.fromRegistries(codecRegistry, CodecRegistries.fromCodecs(jacksonCodec)); } }
public static CodecRegistry codecRegistry() { if (codecRegistry == null) { synchronized (MongoCodecs.class) { if (codecRegistry == null) { Map<BsonType, Class<?>> replacements = new HashMap<BsonType, Class<?>>(); replacements.put(BsonType.TIMESTAMP, Timestamp.class); // make it use ByteArrayCodec instead of BinaryCodec // see also https://jira.mongodb.org/browse/JAVA-2025 replacements.put(BsonType.BINARY, byte[].class); // TODO: replacement for java.sql.Date and java.sql.Time // need a way to add two distinct replacements // can't use DATE_TIME, used for java.util.Date BsonTypeClassMap bsonTypeClassMap = new BsonTypeClassMap(replacements); DocumentCodecProvider documentCodecProvider = new DocumentCodecProvider(bsonTypeClassMap); codecRegistry = CodecRegistries.fromRegistries( CodecRegistries.fromCodecs( new TimestampCodec(), new DateCodec(), new TimeCodec()), CodecRegistries.fromProviders(documentCodecProvider), MongoClient.getDefaultCodecRegistry()); } } } return codecRegistry; }
@Inject public MongoClientWrapper(MongoClientConfiguration configuration) throws UnreachableMongoServerException { try { MongoClientOptions options = toMongoClientOptions(configuration); ImmutableList<MongoCredential> credentials = toMongoCredentials(configuration); testAddress(configuration.getHostAndPort(), options); this.configuration = configuration; this.driverClient = new com.mongodb.MongoClient( new ServerAddress( configuration.getHostAndPort().getHostText(), configuration.getHostAndPort().getPort()), credentials, options ); version = calculateVersion(); codecRegistry = CodecRegistries.fromCodecs(new DocumentCodec()); closed = false; } catch (com.mongodb.MongoException ex) { throw new UnreachableMongoServerException(configuration.getHostAndPort(), ex); } }
@Inject public MongoClientWrapper(MongoClientConfiguration configuration) throws UnreachableMongoServerException { try { MongoClientOptions options = toMongoClientOptions(configuration); ImmutableList<MongoCredential> credentials = toMongoCredentials(configuration); testAddress(configuration.getHostAndPort(), options); this.configuration = configuration; this.driverClient = new com.mongodb.MongoClient( new ServerAddress( configuration.getHostAndPort().getHostText(), configuration.getHostAndPort().getPort()), credentials, options ); version = calculateVersion(); codecRegistry = CodecRegistries.fromCodecs(new DocumentCodec()); closed = false; } catch (com.mongodb.MongoException ex) { throw new UnreachableMongoServerException(configuration.getHostAndPort(), ex); } }
CodecRegistries.fromCodecs(codecs), MongoClient.getDefaultCodecRegistry());
@Bean CodecRegistry codecRegistry() { PojoCodecProvider pojoCodecProvider = PojoCodecProvider .builder() .conventions(ImmutableList.of(CLASS_AND_PROPERTY_CONVENTION)) .register(Context.class) .register(Job.class) .register(TaskExecution.class) .register(Error.class) .register(Accessor.class) .build(); return fromRegistries( fromProviders( new PiperCodecProvider(), pojoCodecProvider, new EnumPropertyCodecProvider()), getDefaultCodecRegistry(), fromCodecs(new StringArrayCodec()) ); }