Packages

object BSONWriter extends BSONWriterCompat

BSONWriter factories.

Linear Supertypes
BSONWriterCompat, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BSONWriter
  2. BSONWriterCompat
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

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](write: (T) ⇒ BSONValue): BSONWriter[T]

    Creates a BSONWriter based on the given write function.

    Creates a BSONWriter based on the given write function. This function is called within a scala.util.Try.

    import reactivemongo.api.bson.{ BSONWriter, BSONString }
    
    case class Foo(value: String)
    
    val foo: BSONWriter[Foo] = BSONWriter { f: Foo => BSONString(f.value) }
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  7. def collect[T](write: PartialFunction[T, BSONValue]): BSONWriter[T]

    Creates a BSONWriter based on the given partial function.

    Creates a BSONWriter based on the given partial function.

    A exceptions.ValueDoesNotMatchException is returned as Failure for any value that is not matched by the write function.

    import reactivemongo.api.bson.{ BSONWriter, BSONInteger }
    
    val strCodeToIntWriter = BSONWriter.collect[String] {
      case "zero" => BSONInteger(0)
      case "one" => BSONInteger(1)
    }
    
    strCodeToIntWriter.writeTry("zero") // Success(BSONInteger(0))
    strCodeToIntWriter.writeTry("one") // Success(BSONInteger(1))
    
    strCodeToIntWriter.writeTry("3")
    // => Failure(ValueDoesNotMatchException(..))
    
    strCodeToIntWriter.writeOpt("4") // None (as failed)
  8. def collectFrom[T](write: PartialFunction[T, Try[BSONValue]]): BSONWriter[T]

    EXPERIMENTAL: Creates a BSONWriter based on the given partially safe write function.

    EXPERIMENTAL: Creates a BSONWriter based on the given partially safe write function.

    A exceptions.ValueDoesNotMatchException is returned as Failure for any value that is not matched by the write function.

    import scala.util.Success
    import reactivemongo.api.bson.{ BSONWriter, BSONInteger }
    
    val strCodeToIntWriter = BSONWriter.collectFrom[String] {
      case "zero" => Success(BSONInteger(0))
      case "one" => Success(BSONInteger(1))
    }
    
    strCodeToIntWriter.writeTry("zero") // Success(BSONInteger(0))
    strCodeToIntWriter.writeTry("one") // Success(BSONInteger(1))
    
    strCodeToIntWriter.writeTry("3")
    // => Failure(IllegalArgumentException(..))
    
    strCodeToIntWriter.writeOpt("4") // None (as failed)
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def from[T](write: (T) ⇒ Try[BSONValue]): BSONWriter[T]

    Creates a BSONWriter based on the given safe write function.

    Creates a BSONWriter based on the given safe write function.

    import scala.util.{ Failure, Success }
    import reactivemongo.api.bson.{ BSONWriter, BSONInteger }
    
    val strCodeToIntWriter = BSONWriter.from[String] {
      case "zero" => Success(BSONInteger(0))
      case "one" => Success(BSONInteger(1))
      case _ => Failure(new IllegalArgumentException())
    }
    
    strCodeToIntWriter.writeTry("zero") // Success(BSONInteger(0))
    strCodeToIntWriter.writeTry("one") // Success(BSONInteger(1))
    
    strCodeToIntWriter.writeTry("3")
    // => Failure(IllegalArgumentException(..))
    
    strCodeToIntWriter.writeOpt("4") // None (as failed)
    write

    the safe function to write T values as BSON

  13. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. def iterable[T, M[_]](write: (T) ⇒ Try[BSONValue])(implicit it: <:<[M[T], Iterable[T]]): BSONWriter[M[T]]

    EXPERIMENTAL: (API may change without notice)

    EXPERIMENTAL: (API may change without notice)

    Creates a BSONWriter accepting only scala.collection.Iterable, and applying the given safe write function to each element value.

    import reactivemongo.api.bson.{ BSONWriter, Macros }
    
    case class Element(str: String, v: Int)
    
    val elementHandler = Macros.handler[Element]
    
    val setWriter: BSONWriter[Set[Element]] =
      BSONWriter.iterable[Element, Set](elementHandler writeTry _)
    Definition Classes
    BSONWriterCompat
  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  20. def option[T](write: (T) ⇒ Option[BSONValue]): BSONWriter[T]

    Creates a BSONWriter based on the given write function.

    Creates a BSONWriter based on the given write function.

    import reactivemongo.api.bson.{ BSONWriter, BSONInteger }
    
    val strCodeToIntWriter = BSONWriter.option[String] {
      case "zero" => Some(BSONInteger(0))
      case "one" => Some(BSONInteger(1))
      case _ => None
    }
    
    strCodeToIntWriter.writeTry("zero") // Success(BSONInteger(0))
    strCodeToIntWriter.writeTry("one") // Success(BSONInteger(1))
    
    strCodeToIntWriter.writeTry("3")
    // => Failure(ValueDoesNotMatchException(..))
    
    strCodeToIntWriter.writeOpt("4") // None (as failed)
  21. def sequence[T](write: (T) ⇒ Try[BSONValue]): BSONWriter[Seq[T]]

    EXPERIMENTAL: (API may change without notice)

    EXPERIMENTAL: (API may change without notice)

    Creates a BSONWriter accepting only scala.collection.Iterable, and applying the given safe write function to each element value.

    import reactivemongo.api.bson.{ BSONWriter, Macros }
    
    case class Element(str: String, v: Int)
    
    val elementHandler = Macros.handler[Element]
    
    val seqWriter: BSONWriter[Seq[Element]] =
      BSONWriter.sequence[Element](elementHandler writeTry _)
  22. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  23. def toString(): String
    Definition Classes
    AnyRef → Any
  24. def tuple2[A, B](implicit arg0: BSONWriter[A], arg1: BSONWriter[B]): BSONWriter[(A, B)]

    EXPERIMENTAL: Creates a BSONWriter that creates tuple elements as BSONArray elements.

    EXPERIMENTAL: Creates a BSONWriter that creates tuple elements as BSONArray elements.

    import reactivemongo.api.bson.BSONWriter
    
    val writer = BSONWriter.tuple2[String, Int]
    
    writer.writeTry("Foo" -> 20)
    // => Success: ['Foo', 20]
  25. def tuple3[A, B, C](implicit arg0: BSONWriter[A], arg1: BSONWriter[B], arg2: BSONWriter[C]): BSONWriter[(A, B, C)]

    EXPERIMENTAL: Creates a BSONWriter that creates tuple elements as BSONArray elements.

  26. def tuple4[A, B, C, D](implicit arg0: BSONWriter[A], arg1: BSONWriter[B], arg2: BSONWriter[C], arg3: BSONWriter[D]): BSONWriter[(A, B, C, D)]

    EXPERIMENTAL: Creates a BSONWriter that creates tuple elements as BSONArray elements.

  27. def tuple5[A, B, C, D, E](implicit arg0: BSONWriter[A], arg1: BSONWriter[B], arg2: BSONWriter[C], arg3: BSONWriter[D], arg4: BSONWriter[E]): BSONWriter[(A, B, C, D, E)]

    EXPERIMENTAL: Creates a BSONWriter that creates tuple elements as BSONArray elements.

  28. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()

Inherited from BSONWriterCompat

Inherited from AnyRef

Inherited from Any

Ungrouped