Class CollectionCodecProvider

java.lang.Object
org.bson.codecs.CollectionCodecProvider
All Implemented Interfaces:
CodecProvider

public class CollectionCodecProvider extends Object implements CodecProvider
A CodecProvider for classes than implement the Collection interface.
Since:
3.3
  • Constructor Details

    • CollectionCodecProvider

      public CollectionCodecProvider()
      Construct a new instance with a default BsonTypeClassMap and no Transformer.
    • CollectionCodecProvider

      public CollectionCodecProvider(Transformer valueTransformer)
      Construct a new instance with a default BsonTypeClassMap and the given Transformer. The transformer is used by the IterableCodec as a last step when decoding values.
      Parameters:
      valueTransformer - the value transformer for decoded values
    • CollectionCodecProvider

      public CollectionCodecProvider(BsonTypeClassMap bsonTypeClassMap)
      Construct a new instance with the given instance of BsonTypeClassMap and no Transformer.
      Parameters:
      bsonTypeClassMap - the non-null BsonTypeClassMap with which to construct instances of DocumentCodec and ListCodec
    • CollectionCodecProvider

      public CollectionCodecProvider(BsonTypeClassMap bsonTypeClassMap, Transformer valueTransformer)
      Construct a new instance with the given instance of BsonTypeClassMap and Transformer.
      Parameters:
      bsonTypeClassMap - the non-null BsonTypeClassMap with which to construct instances of DocumentCodec and ListCodec.
      valueTransformer - the value transformer for decoded values
  • Method Details

    • get

      public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry)
      Description copied from interface: CodecProvider
      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 CodecProvider.get(Class, List, CodecRegistry) is not overridden, or is overridden such that it calls this method.

      Specified by:
      get in interface CodecProvider
      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

      public <T> Codec<T> get(Class<T> clazz, List<Type> typeArguments, CodecRegistry registry)
      Description copied from interface: CodecProvider
      Get a Codec using the given context, which includes, most importantly, the Class for which a Codec is required.

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

      Specified by:
      get in interface CodecProvider
      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
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object