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 Details

    • withUuidRepresentation

      public static CodecRegistry withUuidRepresentation(CodecRegistry codecRegistry, UuidRepresentation uuidRepresentation)
      Apply given UuidRepresentation to the given CodecRegistry.
      Parameters:
      codecRegistry - the code registry
      uuidRepresentation - the uuid representation
      Returns:
      a CodecRegistry with the given UuidRepresentation applied to the given CodecRegistry
      Since:
      4.5
    • fromCodecs

      public static CodecRegistry fromCodecs(Codec<?>... codecs)
      Creates a CodecRegistry from the provided list of Codec 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 - the Codec to create a registry for
      Returns:
      a CodecRegistry for the given list of Codec instances.
    • fromCodecs

      public static CodecRegistry fromCodecs(List<? extends Codec<?>> codecs)
      Creates a CodecRegistry from the provided list of Codec 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 - the Codec to create a registry for
      Returns:
      a CodecRegistry for the given list of Codec instances.
    • fromProviders

      public static CodecRegistry fromProviders(CodecProvider... providers)
      Creates a CodecRegistry from the provided list of CodecProvider instances.

      The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

      Parameters:
      providers - the codec provider
      Returns:
      a CodecRegistry with the ordered list of CodecProvider instances. The registry is also guaranteed to be an instance of {code CodecProvider}, so that when one is passed to fromRegistries(CodecRegistry...) or fromRegistries(java.util.List) it will be treated as a CodecProvider and properly resolve any dependencies between registries.
    • fromProviders

      public static CodecRegistry fromProviders(List<? extends CodecProvider> providers)
      Creates a CodecRegistry from the provided list of CodecProvider instances.

      The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

      Parameters:
      providers - the codec provider
      Returns:
      a CodecRegistry with the ordered list of CodecProvider instances. The registry is also guaranteed to be an instance of {code CodecProvider}, so that when one is passed to fromRegistries(CodecRegistry...) or fromRegistries(java.util.List) it will be treated as a CodecProvider and properly resolve any dependencies between registries.
    • fromRegistries

      public static CodecRegistry fromRegistries(CodecRegistry... registries)
      A CodecRegistry that combines the given CodecRegistry instances into a single registry.

      The registries are checked in order until one returns a Codec for the requested Class.

      The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

      Any of the given registries that also implement CodecProvider will be treated as a CodecProvider instead of a CodecRegistry, which will ensure proper resolution of any dependencies between registries.

      Parameters:
      registries - the preferred registry for Codec lookups
      Returns:
      a CodecRegistry that combines the list of CodecRegistry instances into a single one
    • fromRegistries

      public static CodecRegistry fromRegistries(List<? extends CodecRegistry> registries)
      A CodecRegistry that combines the given CodecRegistry instances into a single registry.

      The registries are checked in order until one returns a Codec for the requested Class.

      The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

      Any of the given registries that also implement CodecProvider will be treated as a CodecProvider instead of a CodecRegistry, which will ensure proper resolution of any dependencies between registries.

      Parameters:
      registries - the preferred registry for Codec lookups
      Returns:
      a CodecRegistry that combines the list of CodecRegistry instances into a single one