Interface CodecProvider

All Known Subinterfaces:
CodecRegistry
All Known Implementing Classes:
BsonCodecProvider, BsonValueCodecProvider, CollectionCodecProvider, DocumentCodecProvider, EnumCodecProvider, IterableCodecProvider, JsonObjectCodecProvider, Jsr310CodecProvider, MapCodecProvider, PojoCodecProvider, UuidCodecProvider, ValueCodecProvider

public interface CodecProvider
A provider of Codec instances. Typically, an instance of a class implementing this interface would be used to construct a CodecRegistry.

While the CodecProvider interface adds no stipulations to the general contract for the Object.equals, programmers who implement the CodecProvider interface "directly" must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementer may wish to implement a "value comparison" in place of the default "reference comparison."

Since:
3.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> Codec<T>
    get(Class<T> clazz, List<Type> typeArguments, CodecRegistry registry)
    Get a Codec using the given context, which includes, most importantly, the Class for which a Codec is required.
    <T> Codec<T>
    get(Class<T> clazz, CodecRegistry registry)
    Get a Codec using the given context, which includes, most importantly, the Class for which a Codec is required.
  • Method Details

    • get

      <T> Codec<T> get(Class<T> clazz, CodecRegistry registry)
      Get a Codec using the given context, which includes, most importantly, the Class for which a Codec is required.

      This method is called by the driver only if get(Class, List, CodecRegistry) is not overridden, or is overridden such that it calls this method.

      Type Parameters:
      T - the type of the class for which a Codec is required
      Parameters:
      clazz - the Class for which to get a Codec
      registry - the registry to use for resolving dependent Codec instances
      Returns:
      the Codec instance, which may be null, if this source is unable to provide one for the requested Class
    • get

      default <T> Codec<T> get(Class<T> clazz, List<Type> typeArguments, CodecRegistry registry)
      Get a Codec using the given context, which includes, most importantly, the Class for which a Codec is required.

      The default implementation delegates to get(Class, CodecRegistry), thus not propagating typeArguments when it uses the registry.

      Type Parameters:
      T - the type of the class for which a Codec is required
      Parameters:
      clazz - the Class for which to get a Codec
      typeArguments - The type arguments for the clazz. The size of the list is either equal to the number of type parameters of the clazz, or is zero. For example, if clazz is Collection.class, then the size of typeArguments is one, since Collection has a single type parameter. The list may be empty either because the clazz is not generic, or because another CodecProvider did not propagate clazz's type arguments to the registry when using it.
      registry - the registry to use for resolving dependent Codec instances
      Returns:
      the Codec instance, which may be null, if this source is unable to provide one for the requested Class
      Since:
      4.10