Packages

object BSONDocumentHandler

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BSONDocumentHandler
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply[T](read: (BSONDocument) => T, write: (T) => BSONDocument): BSONDocumentHandler[T]

    Document handler factory.

    Document handler factory.

    import reactivemongo.api.bson.{ BSONDocument, BSONDocumentHandler }
    
    case class Bar(score: Double)
    
    val h: BSONDocumentHandler[Bar] = BSONDocumentHandler[Bar](
      read = { doc =>
        Bar(doc.getOrElse[Double]("score", 0D))
      },
      write = { bar => BSONDocument("score" -> bar.score) })
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. def collect[T](read: PartialFunction[BSONValue, T], write: PartialFunction[T, BSONDocument]): BSONDocumentHandler[T]

    EXPERIMENTAL: Creates a BSONDocumentHandler based on the given read and write functions.

    EXPERIMENTAL: Creates a BSONDocumentHandler based on the given read and write functions.

    import reactivemongo.api.bson.{ BSONDocumentHandler, BSONDocument }
    
    val handler = BSONDocumentHandler.collect[String](
      read = {
        case doc: BSONDocument => doc.getAsOpt[Int]("value").collect {
          case 0 => "zero"
          case 1 => "one"
        } getOrElse ""
      },
      write = {
        case "zero" => BSONDocument("value" -> 0)
        case "one" => BSONDocument("value" -> 1)
      })
    
    handler.readTry(BSONDocument("value" -> 0)) // Success("zero")
    handler.readOpt(BSONDocument("value" -> 3)) // None (as failed)
    
    handler.writeTry("one") // Success(BSONDocument("value" -> 1))
    handler.writeOpt("3") // None (as failed)
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  11. def from[T](read: (BSONDocument) => Try[T], write: (T) => Try[BSONDocument]): BSONDocumentHandler[T]

    Creates a BSONDocumentHandler based on the given safe read and write functions.

    Creates a BSONDocumentHandler based on the given safe read and write functions.

    import scala.util.Success
    import reactivemongo.api.bson.{ BSONDocument, BSONDocumentHandler }
    
    case class Bar(score: Double)
    
    val h: BSONDocumentHandler[Bar] = BSONDocumentHandler.from[Bar](
      read = _.getAsTry[Double]("score").map(Bar(_)),
      write = { bar => Success(BSONDocument("score" -> bar.score)) })
  12. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. def option[T](read: (BSONValue) => Option[T], write: (T) => Option[BSONDocument]): BSONDocumentHandler[T]

    Creates a BSONDocumentHandler based on the given read and write functions.

    Creates a BSONDocumentHandler based on the given read and write functions.

    import reactivemongo.api.bson.{ BSONDocumentHandler, BSONDocument }
    
    val handler = BSONDocumentHandler.option[String](
      read = {
        case doc: BSONDocument => doc.getAsOpt[Int]("value").collect {
          case 0 => "zero"
          case 1 => "one"
        }
        case _ => None
      },
      write = {
        case "zero" => Some(BSONDocument("value" -> 0))
        case "one" => Some(BSONDocument("value" -> 1))
        case _ => None
      })
    
    handler.readTry(BSONDocument("value" -> 0)) // Success("zero")
    handler.readOpt(BSONDocument("value" -> 3)) // None (as failed)
    
    handler.writeTry("one") // Success(BSONDocument("value" -> 1))
    handler.writeOpt("3") // None (as failed)
  19. def provided[T](implicit reader: BSONDocumentReader[T], writer: BSONDocumentWriter[T]): BSONDocumentHandler[T]

    Returns a document handler for a type T, provided there are a writer and a reader for it.

    Returns a document handler for a type T, provided there are a writer and a reader for it.

    import reactivemongo.api.bson.{
      BSONDocumentHandler, BSONDocumentReader, BSONDocumentWriter
    }
    
    def foo[T](
      implicit r: BSONDocumentReader[T],
        w: BSONDocumentWriter[T]): BSONDocumentHandler[T] =
      BSONDocumentHandler.provided[T]
  20. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  21. def toString(): String
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped