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 CodecRegistry
fromCodecsβ(List<? extends Codec<?>> codecs)
Creates aCodecRegistry
from the provided list ofCodec
instances.static CodecRegistry
fromCodecsβ(Codec<?>... codecs)
Creates aCodecRegistry
from the provided list ofCodec
instances.static CodecRegistry
fromProvidersβ(List<? extends CodecProvider> providers)
Creates aCodecRegistry
from the provided list ofCodecProvider
instances.static CodecRegistry
fromProvidersβ(CodecProvider... providers)
Creates aCodecRegistry
from the provided list ofCodecProvider
instances.static CodecRegistry
fromRegistriesβ(List<? extends CodecRegistry> registries)
ACodecRegistry
that combines the givenCodecRegistry
instances into a single registry.static CodecRegistry
fromRegistriesβ(CodecRegistry... registries)
ACodecRegistry
that combines the givenCodecRegistry
instances into a single registry.
-
-
-
Method Detail
-
fromCodecs
public static CodecRegistry fromCodecsβ(Codec<?>... codecs)
Creates aCodecRegistry
from the provided list ofCodec
instances.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
- theCodec
to create a registry for- Returns:
- a
CodecRegistry
for the given list ofCodec
instances.
-
fromCodecs
public static CodecRegistry fromCodecsβ(List<? extends Codec<?>> codecs)
Creates aCodecRegistry
from the provided list ofCodec
instances.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
- theCodec
to create a registry for- Returns:
- a
CodecRegistry
for the given list ofCodec
instances.
-
fromProviders
public static CodecRegistry fromProvidersβ(CodecProvider... providers)
Creates aCodecRegistry
from the provided list ofCodecProvider
instances.The created instance can handle cycles of
Codec
dependencies, i.e when the construction of aCodec
for class A requires the construction of aCodec
for class B, and vice versa.- Parameters:
providers
- the codec provider- Returns:
- a
CodecRegistry
with the ordered list ofCodecProvider
instances. 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 aCodecProvider
and properly resolve any dependencies between registries.
-
fromProviders
public static CodecRegistry fromProvidersβ(List<? extends CodecProvider> providers)
Creates aCodecRegistry
from the provided list ofCodecProvider
instances.The created instance can handle cycles of
Codec
dependencies, i.e when the construction of aCodec
for class A requires the construction of aCodec
for class B, and vice versa.- Parameters:
providers
- the codec provider- Returns:
- a
CodecRegistry
with the ordered list ofCodecProvider
instances. 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 aCodecProvider
and properly resolve any dependencies between registries.
-
fromRegistries
public static CodecRegistry fromRegistriesβ(CodecRegistry... registries)
ACodecRegistry
that combines the givenCodecRegistry
instances into a single registry.The registries are checked in order until one returns a
Codec
for the requestedClass
.The created instance can handle cycles of
Codec
dependencies, i.e when the construction of aCodec
for class A requires the construction of aCodec
for class B, and vice versa.Any of the given registries that also implement
CodecProvider
will be treated as aCodecProvider
instead of aCodecRegistry
, which will ensure proper resolution of any dependencies between registries.- Parameters:
registries
- the preferred registry forCodec
lookups- Returns:
- a
CodecRegistry
that combines the list ofCodecRegistry
instances into a single one
-
fromRegistries
public static CodecRegistry fromRegistriesβ(List<? extends CodecRegistry> registries)
ACodecRegistry
that combines the givenCodecRegistry
instances into a single registry.The registries are checked in order until one returns a
Codec
for the requestedClass
.The created instance can handle cycles of
Codec
dependencies, i.e when the construction of aCodec
for class A requires the construction of aCodec
for class B, and vice versa.Any of the given registries that also implement
CodecProvider
will be treated as aCodecProvider
instead of aCodecRegistry
, which will ensure proper resolution of any dependencies between registries.- Parameters:
registries
- the preferred registry forCodec
lookups- Returns:
- a
CodecRegistry
that combines the list ofCodecRegistry
instances into a single one
-
-