Interface CollectibleCodec<T>

Type Parameters:
T - the document type
All Superinterfaces:
Codec<T>, Decoder<T>, Encoder<T>
All Known Implementing Classes:
BsonDocumentCodec, DocumentCodec

public interface CollectibleCodec<T> extends Codec<T>
A Codec that generates complete BSON documents for storage in a MongoDB collection.
Since:
3.0
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    documentHasId(T document)
    Returns true if the given document has an _id.
    Generates a value for the _id field on the given document, if the document does not have one.
    getDocumentId(T document)
    Gets the _id of the given document if it contains one, otherwise throws IllegalArgumentException.

    Methods inherited from interface org.bson.codecs.Decoder

    decode

    Methods inherited from interface org.bson.codecs.Encoder

    encode, getEncoderClass
  • Method Details

    • generateIdIfAbsentFromDocument

      T generateIdIfAbsentFromDocument(T document)
      Generates a value for the _id field on the given document, if the document does not have one.
      Parameters:
      document - the document for which to generate a value for the _id.
      Returns:
      the document with the _id
    • documentHasId

      boolean documentHasId(T document)
      Returns true if the given document has an _id.
      Parameters:
      document - the document in which to look for an _id
      Returns:
      true if the document has an _id
    • getDocumentId

      BsonValue getDocumentId(T document)
      Gets the _id of the given document if it contains one, otherwise throws IllegalArgumentException. To avoid the latter case, call documentHasId first to check.
      Parameters:
      document - the document from which to get the _id
      Returns:
      the _id of the document
      Throws:
      IllegalStateException - if the document does not contain an _id