Package org.bson

Interface BSONCallback

All Known Implementing Classes:
BasicBSONCallback, EmptyBSONCallback, LazyBSONCallback

public interface BSONCallback
A callback interface for describing the structure of a BSON document. Implementations of this define how to turn BSON read from MongoDB into Java objects.

See the BSON Spec.

  • Method Details

    • objectStart

      void objectStart()
      Signals the start of a BSON document, which usually maps onto some Java object.
      MongoDB documentation
      MongoDB Documents
    • objectStart

      void objectStart(String name)
      Signals the start of a BSON document, which usually maps onto some Java object.
      Parameters:
      name - the field name of the document.
      MongoDB documentation
      MongoDB Documents
    • objectDone

      Object objectDone()
      Called at the end of the document/array, and returns this object.
      Returns:
      the Object that has been read from this section of the document.
    • reset

      void reset()
      Resets the callback, clearing all state.
    • get

      Object get()
      Returns the finished top-level Document.
      Returns:
      the top level document read from the database.
    • createBSONCallback

      BSONCallback createBSONCallback()
      Factory method for BSONCallbacks.
      Returns:
      a new BSONCallback.
    • arrayStart

      void arrayStart()
      Signals the start of a BSON array.
      MongoDB documentation
      Arrays
    • arrayStart

      void arrayStart(String name)
      Signals the start of a BSON array, with its field name.
      Parameters:
      name - the name of this array field
      MongoDB documentation
      Arrays
    • arrayDone

      Object arrayDone()
      Called the end of the array, and returns the completed array.
      Returns:
      an Object representing the array that has been read from this section of the document.
    • gotNull

      void gotNull(String name)
      Called when reading a BSON field that exists but has a null value.
      Parameters:
      name - the name of the field
      See Also:
    • gotUndefined

      void gotUndefined(String name)
      Called when reading a field with a BsonType.UNDEFINED value.
      Parameters:
      name - the name of the field
      See Also:
    • gotMinKey

      void gotMinKey(String name)
      Called when reading a field with a BsonType.MIN_KEY value.
      Parameters:
      name - the name of the field
    • gotMaxKey

      void gotMaxKey(String name)
      Called when reading a field with a BsonType.MAX_KEY value.
      Parameters:
      name - the name of the field
    • gotBoolean

      void gotBoolean(String name, boolean value)
      Called when reading a field with a BsonType.BOOLEAN value.
      Parameters:
      name - the name of the field
      value - the field's value
    • gotDouble

      void gotDouble(String name, double value)
      Called when reading a field with a BsonType.DOUBLE value.
      Parameters:
      name - the name of the field
      value - the field's value
    • gotDecimal128

      void gotDecimal128(String name, Decimal128 value)
      Called when reading a field with a BsonType.DECIMAL128 value.
      Parameters:
      name - the field name
      value - the Decimal128 field value
      Since:
      3.4
      Since server release
      3.4
    • gotInt

      void gotInt(String name, int value)
      Called when reading a field with a BsonType.INT32 value.
      Parameters:
      name - the name of the field
      value - the field's value
    • gotLong

      void gotLong(String name, long value)
      Called when reading a field with a BsonType.INT64 value.
      Parameters:
      name - the name of the field
      value - the field's value
    • gotDate

      void gotDate(String name, long millis)
      Called when reading a field with a BsonType.DATE_TIME value.
      Parameters:
      name - the name of the field
      millis - the date and time in milliseconds
    • gotString

      void gotString(String name, String value)
      Called when reading a field with a BsonType.STRING value.
      Parameters:
      name - the name of the field
      value - the field's value
    • gotSymbol

      void gotSymbol(String name, String value)
      Called when reading a field with a BsonType.SYMBOL value.
      Parameters:
      name - the name of the field
      value - the field's value
    • gotRegex

      void gotRegex(String name, String pattern, String flags)
      Called when reading a field with a BsonType.REGULAR_EXPRESSION value.
      Parameters:
      name - the name of the field
      pattern - the regex pattern
      flags - the optional flags for the regular expression
      MongoDB documentation
      $regex
    • gotTimestamp

      void gotTimestamp(String name, int time, int increment)
      Called when reading a field with a BsonType.TIMESTAMP value.
      Parameters:
      name - the name of the field
      time - the time in seconds since epoch
      increment - an incrementing ordinal for operations within a given second
      MongoDB documentation
      Timestamps
    • gotObjectId

      void gotObjectId(String name, ObjectId id)
      Called when reading a field with a BsonType.OBJECT_ID value.
      Parameters:
      name - the name of the field
      id - the object ID
    • gotDBRef

      void gotDBRef(String name, String namespace, ObjectId id)
      Invoked when BSONDecoder encountered a BsonType.DB_POINTER type field in a byte sequence.
      Parameters:
      name - the name of the field
      namespace - the namespace to which reference is pointing to
      id - the if of the object to which reference is pointing to
    • gotBinary

      void gotBinary(String name, byte type, byte[] data)
      Called when reading a field with a BsonType.BINARY value. Note that binary values have a subtype, which may determine how the value is processed.
      Parameters:
      name - the name of the field
      type - one of the binary subtypes: BsonBinarySubType
      data - the field's value
    • gotUUID

      void gotUUID(String name, long part1, long part2)
      Called when reading a field with a UUID value. This is a binary value of subtype BsonBinarySubType.UUID_LEGACY
      Parameters:
      name - the name of the field
      part1 - the first part of the UUID
      part2 - the second part of the UUID
    • gotCode

      void gotCode(String name, String code)
      Called when reading a field with a BsonType.JAVASCRIPT value.
      Parameters:
      name - the name of the field
      code - the JavaScript code
    • gotCodeWScope

      void gotCodeWScope(String name, String code, Object scope)
      Called when reading a field with a BsonType.JAVASCRIPT_WITH_SCOPE value.
      Parameters:
      name - the name of the field
      code - the JavaScript code
      scope - a document representing the scope for the code