public class BsonDocumentCodec extends Object implements CollectibleCodec<BsonDocument>
Constructor and Description |
---|
BsonDocumentCodec()
Creates a new instance with a default codec registry that uses the
BsonValueCodecProvider . |
BsonDocumentCodec(CodecRegistry codecRegistry)
Creates a new instance initialised with the given codec registry.
|
Modifier and Type | Method and Description |
---|---|
BsonDocument |
decode(BsonReader reader,
DecoderContext decoderContext)
Decodes a BSON value from the given reader into an instance of the type parameter
T . |
boolean |
documentHasId(BsonDocument document)
Returns true if the given document has an _id.
|
void |
encode(BsonWriter writer,
BsonDocument value,
EncoderContext encoderContext)
Encode an instance of the type parameter
T into a BSON value. |
BsonDocument |
generateIdIfAbsentFromDocument(BsonDocument document)
Generates a value for the _id field on the given document, if the document does not have one.
|
CodecRegistry |
getCodecRegistry()
Gets the
CodecRegistry for this Codec . |
BsonValue |
getDocumentId(BsonDocument document)
Gets the _id of the given document if it contains one, otherwise throws
IllegalArgumentException . |
Class<BsonDocument> |
getEncoderClass()
Returns the Class instance that this encodes.
|
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 . |
public BsonDocumentCodec()
BsonValueCodecProvider
.public BsonDocumentCodec(CodecRegistry codecRegistry)
codecRegistry
- the CodecRegistry
to use to look up the codecs for encoding and decoding to/from BSONpublic CodecRegistry getCodecRegistry()
CodecRegistry
for this Codec
.public BsonDocument decode(BsonReader reader, DecoderContext decoderContext)
Decoder
T
.decode
in interface Decoder<BsonDocument>
reader
- the BSON readerdecoderContext
- the decoder contextT
.protected BsonValue readValue(BsonReader reader, DecoderContext decoderContext)
BsonReader
. It is required
that the value be fully consumed before returning.reader
- the read to read the value fromdecoderContext
- the contextpublic void encode(BsonWriter writer, BsonDocument value, EncoderContext encoderContext)
Encoder
T
into a BSON value.encode
in interface Encoder<BsonDocument>
writer
- the BSON writer to encode intovalue
- the value to encodeencoderContext
- the encoder contextpublic Class<BsonDocument> getEncoderClass()
Encoder
getEncoderClass
in interface Encoder<BsonDocument>
public BsonDocument generateIdIfAbsentFromDocument(BsonDocument document)
CollectibleCodec
generateIdIfAbsentFromDocument
in interface CollectibleCodec<BsonDocument>
document
- the document for which to generate a value for the _id.public boolean documentHasId(BsonDocument document)
CollectibleCodec
documentHasId
in interface CollectibleCodec<BsonDocument>
document
- the document in which to look for an _idpublic BsonValue getDocumentId(BsonDocument document)
CollectibleCodec
IllegalArgumentException
. To avoid the latter case,
call documentHasId
first to check.getDocumentId
in interface CollectibleCodec<BsonDocument>
document
- the document from which to get the _id