Object/Trait

reactivemongo.api.bson

BSONDocumentHandler

Related Docs: trait BSONDocumentHandler | package bson

Permalink

object BSONDocumentHandler

BSONDocumentHandler factories

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. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def apply[T](read: (BSONDocument) ⇒ T, write: (T) ⇒ BSONDocument): BSONDocumentHandler[T]

    Permalink

    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

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def collect[T](read: PartialFunction[BSONValue, T], write: PartialFunction[T, BSONDocument]): BSONDocumentHandler[T]

    Permalink

    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

    Permalink
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. def from[T](read: (BSONDocument) ⇒ Try[T], write: (T) ⇒ Try[BSONDocument]): BSONDocumentHandler[T]

    Permalink

    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[_]

    Permalink
    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. def option[T](read: (BSONValue) ⇒ Option[T], write: (T) ⇒ Option[BSONDocument]): BSONDocumentHandler[T]

    Permalink

    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]

    Permalink

    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

    Permalink
    Definition Classes
    AnyRef
  21. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped