Package com.mongodb

Class DBObjectCodec

    • Constructor Detail

      • DBObjectCodec

        public DBObjectCodec()
        Construct an instance with the default codec registry
        Since:
        3.7
      • DBObjectCodec

        public DBObjectCodec(CodecRegistry codecRegistry)
        Construct an instance with the given codec registry.
        Parameters:
        codecRegistry - the non-null codec registry
      • DBObjectCodec

        public DBObjectCodec(CodecRegistry codecRegistry,
                             BsonTypeClassMap bsonTypeClassMap)
        Construct an instance.
        Parameters:
        codecRegistry - the codec registry
        bsonTypeClassMap - the non-null BsonTypeClassMap
      • DBObjectCodec

        public DBObjectCodec(CodecRegistry codecRegistry,
                             BsonTypeClassMap bsonTypeClassMap,
                             com.mongodb.DBObjectFactory objectFactory)
        Construct an instance.
        Parameters:
        codecRegistry - the non-null codec registry
        bsonTypeClassMap - the non-null BsonTypeClassMap
        objectFactory - the non-null object factory used to create empty DBObject instances when decoding
    • Method Detail

      • encode

        public void encode(BsonWriter writer,
                           DBObject document,
                           EncoderContext encoderContext)
        Description copied from interface: Encoder
        Encode an instance of the type parameter T into a BSON value.
        Specified by:
        encode in interface Encoder<DBObject>
        Parameters:
        writer - the BSON writer to encode into
        document - the value to encode
        encoderContext - the encoder context
      • decode

        public DBObject decode(BsonReader reader,
                               DecoderContext decoderContext)
        Description copied from interface: Decoder
        Decodes a BSON value from the given reader into an instance of the type parameter T.
        Specified by:
        decode in interface Decoder<DBObject>
        Parameters:
        reader - the BSON reader
        decoderContext - the decoder context
        Returns:
        an instance of the type parameter T.
      • getEncoderClass

        public Class<DBObject> getEncoderClass()
        Description copied from interface: Encoder
        Returns the Class instance that this encodes. This is necessary because Java does not reify generic types.
        Specified by:
        getEncoderClass in interface Encoder<DBObject>
        Returns:
        the Class instance that this encodes.
      • documentHasId

        public boolean documentHasId(DBObject document)
        Description copied from interface: CollectibleCodec
        Returns true if the given document has an _id.
        Specified by:
        documentHasId in interface CollectibleCodec<DBObject>
        Parameters:
        document - the document in which to look for an _id
        Returns:
        true if the document has an _id
      • getDocumentId

        public BsonValue getDocumentId(DBObject document)
        Description copied from interface: CollectibleCodec
        Gets the _id of the given document if it contains one, otherwise throws IllegalArgumentException. To avoid the latter case, call documentHasId first to check.
        Specified by:
        getDocumentId in interface CollectibleCodec<DBObject>
        Parameters:
        document - the document from which to get the _id
        Returns:
        the _id of the document
      • generateIdIfAbsentFromDocument

        public DBObject generateIdIfAbsentFromDocument(DBObject document)
        Description copied from interface: CollectibleCodec
        Generates a value for the _id field on the given document, if the document does not have one.
        Specified by:
        generateIdIfAbsentFromDocument in interface CollectibleCodec<DBObject>
        Parameters:
        document - the document for which to generate a value for the _id.
        Returns:
        the document with the _id