public class DBObjectCodec extends java.lang.Object implements CollectibleCodec<DBObject>
Modifier and Type | Field and Description |
---|---|
private BsonTypeCodecMap |
bsonTypeCodecMap |
private CodecRegistry |
codecRegistry |
private static BsonTypeClassMap |
DEFAULT_BSON_TYPE_CLASS_MAP |
private static java.lang.String |
ID_FIELD_NAME |
private IdGenerator |
idGenerator |
private DBObjectFactory |
objectFactory |
Constructor and Description |
---|
DBObjectCodec(CodecRegistry codecRegistry)
Construct an instance with the given codec registry.
|
DBObjectCodec(CodecRegistry codecRegistry,
BsonTypeClassMap bsonTypeClassMap)
Construct an instance.
|
DBObjectCodec(CodecRegistry codecRegistry,
BsonTypeClassMap bsonTypeClassMap,
DBObjectFactory objectFactory)
Construct an instance.
|
Modifier and Type | Method and Description |
---|---|
private void |
beforeFields(BsonWriter bsonWriter,
EncoderContext encoderContext,
DBObject document) |
(package private) static BsonTypeClassMap |
createDefaultBsonTypeClassMap() |
DBObject |
decode(BsonReader reader,
DecoderContext decoderContext)
Decodes a BSON value from the given reader into an instance of the type parameter
T . |
boolean |
documentHasId(DBObject document)
Returns true if the given document has an _id.
|
void |
encode(BsonWriter writer,
DBObject document,
EncoderContext encoderContext)
Encode an instance of the type parameter
T into a BSON value. |
private void |
encodeArray(BsonWriter bsonWriter,
java.lang.Object value) |
private void |
encodeBsonObject(BsonWriter bsonWriter,
BSONObject document) |
private void |
encodeByteArray(BsonWriter bsonWriter,
byte[] value) |
private void |
encodeCodeWScope(BsonWriter bsonWriter,
CodeWScope value) |
private void |
encodeDBRef(BsonWriter bsonWriter,
DBRef dbRef) |
private void |
encodeIterable(BsonWriter bsonWriter,
java.lang.Iterable iterable) |
private void |
encodeMap(BsonWriter bsonWriter,
java.util.Map<java.lang.String,java.lang.Object> document) |
DBObject |
generateIdIfAbsentFromDocument(DBObject document)
Generates a value for the _id field on the given document, if the document does not have one.
|
(package private) static BsonTypeClassMap |
getDefaultBsonTypeClassMap() |
BsonValue |
getDocumentId(DBObject document)
Gets the _id of the given document if it contains one, otherwise throws
IllegalArgumentException . |
java.lang.Class<DBObject> |
getEncoderClass()
Returns the Class instance that this encodes.
|
private java.util.List |
readArray(BsonReader reader,
DecoderContext decoderContext,
java.util.List<java.lang.String> path) |
private java.lang.Object |
readBinary(BsonReader reader,
DecoderContext decoderContext) |
private CodeWScope |
readCodeWScope(BsonReader reader,
DecoderContext decoderContext,
java.util.List<java.lang.String> path) |
private DBObject |
readDocument(BsonReader reader,
DecoderContext decoderContext,
java.util.List<java.lang.String> path) |
private java.lang.Object |
readValue(BsonReader reader,
DecoderContext decoderContext,
java.lang.String fieldName,
java.util.List<java.lang.String> path) |
private boolean |
skipField(EncoderContext encoderContext,
java.lang.String key) |
private java.lang.Object |
verifyForDBRef(DBObject document) |
private void |
writeValue(BsonWriter bsonWriter,
EncoderContext encoderContext,
java.lang.Object initialValue) |
private static final BsonTypeClassMap DEFAULT_BSON_TYPE_CLASS_MAP
private static final java.lang.String ID_FIELD_NAME
private final CodecRegistry codecRegistry
private final BsonTypeCodecMap bsonTypeCodecMap
private final DBObjectFactory objectFactory
private final IdGenerator idGenerator
public DBObjectCodec(CodecRegistry codecRegistry)
codecRegistry
- the non-null codec registrypublic DBObjectCodec(CodecRegistry codecRegistry, BsonTypeClassMap bsonTypeClassMap)
codecRegistry
- the codec registrybsonTypeClassMap
- the non-null BsonTypeClassMappublic DBObjectCodec(CodecRegistry codecRegistry, BsonTypeClassMap bsonTypeClassMap, DBObjectFactory objectFactory)
codecRegistry
- the non-null codec registrybsonTypeClassMap
- the non-null BsonTypeClassMapobjectFactory
- the non-null object factory used to create empty DBObject instances when decodingstatic BsonTypeClassMap createDefaultBsonTypeClassMap()
static BsonTypeClassMap getDefaultBsonTypeClassMap()
public void encode(BsonWriter writer, DBObject document, EncoderContext encoderContext)
Encoder
T
into a BSON value.public DBObject decode(BsonReader reader, DecoderContext decoderContext)
Decoder
T
.public java.lang.Class<DBObject> getEncoderClass()
Encoder
getEncoderClass
in interface Encoder<DBObject>
public boolean documentHasId(DBObject document)
CollectibleCodec
documentHasId
in interface CollectibleCodec<DBObject>
document
- the document in which to look for an _idpublic BsonValue getDocumentId(DBObject document)
CollectibleCodec
IllegalArgumentException
. To avoid the latter case,
call documentHasId
first to check.getDocumentId
in interface CollectibleCodec<DBObject>
document
- the document from which to get the _idpublic DBObject generateIdIfAbsentFromDocument(DBObject document)
CollectibleCodec
generateIdIfAbsentFromDocument
in interface CollectibleCodec<DBObject>
document
- the document for which to generate a value for the _id.private void beforeFields(BsonWriter bsonWriter, EncoderContext encoderContext, DBObject document)
private boolean skipField(EncoderContext encoderContext, java.lang.String key)
private void writeValue(BsonWriter bsonWriter, EncoderContext encoderContext, java.lang.Object initialValue)
private void encodeMap(BsonWriter bsonWriter, java.util.Map<java.lang.String,java.lang.Object> document)
private void encodeBsonObject(BsonWriter bsonWriter, BSONObject document)
private void encodeByteArray(BsonWriter bsonWriter, byte[] value)
private void encodeArray(BsonWriter bsonWriter, java.lang.Object value)
private void encodeDBRef(BsonWriter bsonWriter, DBRef dbRef)
private void encodeCodeWScope(BsonWriter bsonWriter, CodeWScope value)
private void encodeIterable(BsonWriter bsonWriter, java.lang.Iterable iterable)
private java.lang.Object readValue(BsonReader reader, DecoderContext decoderContext, java.lang.String fieldName, java.util.List<java.lang.String> path)
private java.lang.Object readBinary(BsonReader reader, DecoderContext decoderContext)
private java.util.List readArray(BsonReader reader, DecoderContext decoderContext, java.util.List<java.lang.String> path)
private DBObject readDocument(BsonReader reader, DecoderContext decoderContext, java.util.List<java.lang.String> path)
private CodeWScope readCodeWScope(BsonReader reader, DecoderContext decoderContext, java.util.List<java.lang.String> path)
private java.lang.Object verifyForDBRef(DBObject document)