Class BsonValueCodec

java.lang.Object
org.bson.codecs.BsonValueCodec
All Implemented Interfaces:
Codec<BsonValue>, Decoder<BsonValue>, Encoder<BsonValue>

public class BsonValueCodec extends Object implements Codec<BsonValue>
A codec for unknown BsonValues.

Useful for decoding a mix of differing Bson types.

Since:
3.0
  • Constructor Details

    • BsonValueCodec

      public BsonValueCodec()
      Creates a new instance with a default codec registry that uses the BsonValueCodecProvider.
    • BsonValueCodec

      public BsonValueCodec(CodecRegistry codecRegistry)
      Creates a new instance initialised with the given codec registry.
      Parameters:
      codecRegistry - the CodecRegistry to use to look up the codecs for encoding and decoding to/from BSON
  • Method Details

    • decode

      public BsonValue 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<BsonValue>
      Parameters:
      reader - the BSON reader
      decoderContext - the decoder context
      Returns:
      an instance of the type parameter T.
    • encode

      public void encode(BsonWriter writer, BsonValue value, 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<BsonValue>
      Parameters:
      writer - the BSON writer to encode into
      value - the value to encode
      encoderContext - the encoder context
    • getEncoderClass

      public Class<BsonValue> 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<BsonValue>
      Returns:
      the Class instance that this encodes.