Class BsonDocumentCodec

    • Constructor Detail

      • BsonDocumentCodec

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

        public BsonDocumentCodec​(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 Detail

      • getCodecRegistry

        public CodecRegistry getCodecRegistry()
        Gets the CodecRegistry for this Codec.
        Returns:
        the registry
      • decode

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

        protected BsonValue readValue​(BsonReader reader,
                                      DecoderContext decoderContext)
        This method may be overridden to change the behavior of reading the current value from the given BsonReader. It is required that the value be fully consumed before returning.
        Parameters:
        reader - the read to read the value from
        decoderContext - the context
        Returns:
        the non-null value read from the reader
      • encode

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

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

        public boolean documentHasId​(BsonDocument document)
        Description copied from interface: CollectibleCodec
        Returns true if the given document has an _id.
        Specified by:
        documentHasId in interface CollectibleCodec<BsonDocument>
        Parameters:
        document - the document in which to look for an _id
        Returns:
        true if the document has an _id
      • getDocumentId

        public BsonValue getDocumentId​(BsonDocument document)
        Description copied from interface: CollectibleCodec
        Gets the _id of the given document if it contains one, otherwise throws IllegalArgumentException. To avoid the latter case, call documentHasId first to check.
        Specified by:
        getDocumentId in interface CollectibleCodec<BsonDocument>
        Parameters:
        document - the document from which to get the _id
        Returns:
        the _id of the document