Class MapCodec

    • Constructor Detail

      • MapCodec

        public MapCodec​()
        Construct a new instance with a default CodecRegistry
      • MapCodec

        public MapCodec​(CodecRegistry registry)
        Construct a new instance with the given registry
        Parameters:
        registry - the registry
      • MapCodec

        public MapCodec​(CodecRegistry registry,
                        BsonTypeClassMap bsonTypeClassMap)
        Construct a new instance with the given registry and BSON type class map.
        Parameters:
        registry - the registry
        bsonTypeClassMap - the BSON type class map
      • MapCodec

        public MapCodec​(CodecRegistry registry,
                        BsonTypeClassMap bsonTypeClassMap,
                        Transformer valueTransformer)
        Construct a new instance with the given registry and BSON type class map. The transformer is applied as a last step when decoding values, which allows users of this codec to control the decoding process. For example, a user of this class could substitute a value decoded as a Document with an instance of a special purpose class (e.g., one representing a DBRef in MongoDB).
        Parameters:
        registry - the registry
        bsonTypeClassMap - the BSON type class map
        valueTransformer - the value transformer to use as a final step when decoding the value of any field in the map
    • Method Detail

      • encode

        public void encode​(BsonWriter writer,
                           Map<String,Object> map,
                           EncoderContext encoderContext)
        Description copied from interface: Encoder
        Encode an instance of the type parameter T into a BSON value.
        Specified by:
        encode in interface Encoder<Map<String,Object>>
        Parameters:
        writer - the BSON writer to encode into
        map - the value to encode
        encoderContext - the encoder context
      • decode

        public Map<String,Object> decode​(BsonReader reader,
                                         DecoderContext decoderContext)
        Description copied from interface: Decoder
        Decodes a BSON value from the given reader into an instance of the type parameter T.
        Specified by:
        decode in interface Decoder<Map<String,Object>>
        Parameters:
        reader - the BSON reader
        decoderContext - the decoder context
        Returns:
        an instance of the type parameter T.
      • getEncoderClass

        public Class<Map<String,Object>> getEncoderClass​()
        Description copied from interface: Encoder
        Returns the Class instance that this encodes. This is necessary because Java does not reify generic types.
        Specified by:
        getEncoderClass in interface Encoder<Map<String,Object>>
        Returns:
        the Class instance that this encodes.