Constructor and Description |
---|
DocumentCodec()
Construct a new instance with a default
CodecRegistry . |
DocumentCodec(CodecRegistry registry)
Construct a new instance with the given registry.
|
DocumentCodec(CodecRegistry registry,
BsonTypeClassMap bsonTypeClassMap)
Construct a new instance with the given registry and BSON type class map.
|
DocumentCodec(CodecRegistry registry,
BsonTypeClassMap bsonTypeClassMap,
Transformer valueTransformer)
Construct a new instance with the given registry and BSON type class map.
|
Modifier and Type | Method and Description |
---|---|
Document |
decode(BsonReader reader,
DecoderContext decoderContext)
Decodes a BSON value from the given reader into an instance of the type parameter
T . |
boolean |
documentHasId(Document document)
Returns true if the given document has an _id.
|
void |
encode(BsonWriter writer,
Document document,
EncoderContext encoderContext)
Encode an instance of the type parameter
T into a BSON value. |
Document |
generateIdIfAbsentFromDocument(Document document)
Generates a value for the _id field on the given document, if the document does not have one.
|
BsonValue |
getDocumentId(Document document)
Gets the _id of the given document if it contains one, otherwise throws
IllegalArgumentException . |
java.lang.Class<Document> |
getEncoderClass()
Returns the Class instance that this encodes.
|
public DocumentCodec()
CodecRegistry
.public DocumentCodec(CodecRegistry registry)
registry
- the registrypublic DocumentCodec(CodecRegistry registry, BsonTypeClassMap bsonTypeClassMap)
registry
- the registrybsonTypeClassMap
- the BSON type class mappublic DocumentCodec(CodecRegistry registry, BsonTypeClassMap bsonTypeClassMap, Transformer valueTransformer)
registry
- the registrybsonTypeClassMap
- the BSON type class mapvalueTransformer
- the value transformer to use as a final step when decoding the value of any field in the documentpublic boolean documentHasId(Document document)
CollectibleCodec
documentHasId
in interface CollectibleCodec<Document>
document
- the document in which to look for an _idpublic BsonValue getDocumentId(Document document)
CollectibleCodec
IllegalArgumentException
. To avoid the latter case,
call documentHasId
first to check.getDocumentId
in interface CollectibleCodec<Document>
document
- the document from which to get the _idpublic Document generateIdIfAbsentFromDocument(Document document)
CollectibleCodec
generateIdIfAbsentFromDocument
in interface CollectibleCodec<Document>
document
- the document for which to generate a value for the _id.public void encode(BsonWriter writer, Document document, EncoderContext encoderContext)
Encoder
T
into a BSON value.public Document decode(BsonReader reader, DecoderContext decoderContext)
Decoder
T
.public java.lang.Class<Document> getEncoderClass()
Encoder
getEncoderClass
in interface Encoder<Document>
Copyright © 2010 - 2020 Adobe. All Rights Reserved