Class CodecRegistries
- java.lang.Object
-
- org.bson.codecs.configuration.CodecRegistries
-
public final class CodecRegistries extends java.lang.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(java.util.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(java.util.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(java.util.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(java.util.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(java.util.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(java.util.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
-
-