public class BsonDocumentCodec extends java.lang.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 . |
java.lang.Class<BsonDocument> |
getEncoderClass()
Returns the Class instance that this encodes.
|
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
.public 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 java.lang.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 _idCopyright © 2010 - 2020 Adobe. All Rights Reserved