Modifier and Type | Field and Description |
---|---|
private BsonTypeCodecMap |
bsonTypeCodecMap |
private static BsonTypeClassMap |
DEFAULT_BSON_TYPE_CLASS_MAP |
private static CodecRegistry |
DEFAULT_REGISTRY |
private static java.lang.String |
ID_FIELD_NAME |
private IdGenerator |
idGenerator |
private CodecRegistry |
registry |
private Transformer |
valueTransformer |
Constructor and Description |
---|
DocumentCodec()
Construct a new instance with a default
CodecRegistry and |
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 |
---|---|
private void |
beforeFields(BsonWriter bsonWriter,
EncoderContext encoderContext,
java.util.Map<java.lang.String,java.lang.Object> document) |
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.
|
private java.util.List<java.lang.Object> |
readList(BsonReader reader,
DecoderContext decoderContext) |
private java.lang.Object |
readValue(BsonReader reader,
DecoderContext decoderContext) |
private boolean |
skipField(EncoderContext encoderContext,
java.lang.String key) |
private void |
writeIterable(BsonWriter writer,
java.lang.Iterable<java.lang.Object> list,
EncoderContext encoderContext) |
private void |
writeMap(BsonWriter writer,
java.util.Map<java.lang.String,java.lang.Object> map,
EncoderContext encoderContext) |
private void |
writeValue(BsonWriter writer,
EncoderContext encoderContext,
java.lang.Object value) |
private static final java.lang.String ID_FIELD_NAME
private static final CodecRegistry DEFAULT_REGISTRY
private static final BsonTypeClassMap DEFAULT_BSON_TYPE_CLASS_MAP
private final BsonTypeCodecMap bsonTypeCodecMap
private final CodecRegistry registry
private final IdGenerator idGenerator
private final Transformer valueTransformer
public DocumentCodec()
CodecRegistry
andpublic 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>
private void beforeFields(BsonWriter bsonWriter, EncoderContext encoderContext, java.util.Map<java.lang.String,java.lang.Object> document)
private boolean skipField(EncoderContext encoderContext, java.lang.String key)
private void writeValue(BsonWriter writer, EncoderContext encoderContext, java.lang.Object value)
private void writeMap(BsonWriter writer, java.util.Map<java.lang.String,java.lang.Object> map, EncoderContext encoderContext)
private void writeIterable(BsonWriter writer, java.lang.Iterable<java.lang.Object> list, EncoderContext encoderContext)
private java.lang.Object readValue(BsonReader reader, DecoderContext decoderContext)
private java.util.List<java.lang.Object> readList(BsonReader reader, DecoderContext decoderContext)