Class CodecRegistries
- java.lang.Object
-
- org.bson.codecs.configuration.CodecRegistries
-
public final class CodecRegistries extends Object
A helper class for creating and combining codecs, codec providers, and codec registries- Since:
- 3.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CodecRegistryfromCodecs(List<? extends Codec<?>> codecs)Creates aCodecRegistryfrom the provided list ofCodecinstances.static CodecRegistryfromCodecs(Codec<?>... codecs)Creates aCodecRegistryfrom the provided list ofCodecinstances.static CodecRegistryfromProviders(List<? extends CodecProvider> providers)Creates aCodecRegistryfrom the provided list ofCodecProviderinstances.static CodecRegistryfromProviders(CodecProvider... providers)Creates aCodecRegistryfrom the provided list ofCodecProviderinstances.static CodecRegistryfromRegistries(List<? extends CodecRegistry> registries)ACodecRegistrythat combines the givenCodecRegistryinstances into a single registry.static CodecRegistryfromRegistries(CodecRegistry... registries)ACodecRegistrythat combines the givenCodecRegistryinstances into a single registry.
-
-
-
Method Detail
-
fromCodecs
public static CodecRegistry fromCodecs(Codec<?>... codecs)
Creates aCodecRegistryfrom the provided list ofCodecinstances.This registry can then be used alongside other registries. Typically used when adding extra codecs to existing codecs with the
fromRegistries(CodecRegistry...))} helper.- Parameters:
codecs- theCodecto create a registry for- Returns:
- a
CodecRegistryfor the given list ofCodecinstances.
-
fromCodecs
public static CodecRegistry fromCodecs(List<? extends Codec<?>> codecs)
Creates aCodecRegistryfrom the provided list ofCodecinstances.This registry can then be used alongside other registries. Typically used when adding extra codecs to existing codecs with the
fromRegistries(CodecRegistry...))} helper.- Parameters:
codecs- theCodecto create a registry for- Returns:
- a
CodecRegistryfor the given list ofCodecinstances.
-
fromProviders
public static CodecRegistry fromProviders(CodecProvider... providers)
Creates aCodecRegistryfrom the provided list ofCodecProviderinstances.The created instance can handle cycles of
Codecdependencies, i.e when the construction of aCodecfor class A requires the construction of aCodecfor class B, and vice versa.- Parameters:
providers- the codec provider- Returns:
- a
CodecRegistrywith the ordered list ofCodecProviderinstances. The registry is also guaranteed to be an instance of {code CodecProvider}, so that when one is passed tofromRegistries(CodecRegistry...)orfromRegistries(java.util.List)it will be treated as aCodecProviderand properly resolve any dependencies between registries.
-
fromProviders
public static CodecRegistry fromProviders(List<? extends CodecProvider> providers)
Creates aCodecRegistryfrom the provided list ofCodecProviderinstances.The created instance can handle cycles of
Codecdependencies, i.e when the construction of aCodecfor class A requires the construction of aCodecfor class B, and vice versa.- Parameters:
providers- the codec provider- Returns:
- a
CodecRegistrywith the ordered list ofCodecProviderinstances. The registry is also guaranteed to be an instance of {code CodecProvider}, so that when one is passed tofromRegistries(CodecRegistry...)orfromRegistries(java.util.List)it will be treated as aCodecProviderand properly resolve any dependencies between registries.
-
fromRegistries
public static CodecRegistry fromRegistries(CodecRegistry... registries)
ACodecRegistrythat combines the givenCodecRegistryinstances into a single registry.The registries are checked in order until one returns a
Codecfor the requestedClass.The created instance can handle cycles of
Codecdependencies, i.e when the construction of aCodecfor class A requires the construction of aCodecfor class B, and vice versa.Any of the given registries that also implement
CodecProviderwill be treated as aCodecProviderinstead of aCodecRegistry, which will ensure proper resolution of any dependencies between registries.- Parameters:
registries- the preferred registry forCodeclookups- Returns:
- a
CodecRegistrythat combines the list ofCodecRegistryinstances into a single one
-
fromRegistries
public static CodecRegistry fromRegistries(List<? extends CodecRegistry> registries)
ACodecRegistrythat combines the givenCodecRegistryinstances into a single registry.The registries are checked in order until one returns a
Codecfor the requestedClass.The created instance can handle cycles of
Codecdependencies, i.e when the construction of aCodecfor class A requires the construction of aCodecfor class B, and vice versa.Any of the given registries that also implement
CodecProviderwill be treated as aCodecProviderinstead of aCodecRegistry, which will ensure proper resolution of any dependencies between registries.- Parameters:
registries- the preferred registry forCodeclookups- Returns:
- a
CodecRegistrythat combines the list ofCodecRegistryinstances into a single one
-
-