BSONWriter

reactivemongo.api.bson.BSONWriter
See theBSONWriter companion object
trait BSONWriter[T]

A writer that produces a subtype of BSONValue from an instance of T.

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Handler.type
object Handler.type
trait BSONHandler[T]
object BSONBinaryHandler.type
object BSONBooleanHandler.type
object BSONByteHandler.type
object BSONCharHandler.type
object BSONDecimalHandler.type
object BSONDoubleHandler.type
object BSONFloatHandler.type
object BSONIntegerHandler.type
object BSONLocaleHandler.type
object BSONLongHandler.type
object BSONShortHandler.type
object BSONStringHandler.type
object BSONURIHandler.type
object BSONURLHandler.type
object BSONUUIDHandler.type
object Handler.type

Members list

Concise view

Value members

Abstract methods

def writeTry(t: T): Try[BSONValue]

Tries to produce a BSON value from an instance of T.

Tries to produce a BSON value from an instance of T.

import scala.util.Try
import reactivemongo.api.bson.{ BSONWriter, BSONValue }

def toBSON[T](value: T)(implicit w: BSONWriter[T]): Try[BSONValue] =
 w.writeTry(value)

Attributes

Concrete methods

Prepares a BSON writer that returns the result of applying f on the BSON value from this writer.

Prepares a BSON writer that returns the result of applying f on the BSON value from this writer.

If the f function is not defined for a BSONValue, it will results in a Failure.

Attributes

f

the partial function to apply

Prepares a BSON writer that returns the result of applying f on the BSON value from this writer.

Prepares a BSON writer that returns the result of applying f on the BSON value from this writer.

Attributes

f

the safe function to apply

def beforeWrite[U](f: U => T): BSONWriter[U]

Prepares a BSON writer that converts the input before calling the current writer.

Prepares a BSON writer that converts the input before calling the current writer.

Attributes

f

the function apply the U input value to convert at T value used to the current writer

import reactivemongo.api.bson.BSONWriter
val w: BSONWriter[String] =
 implicitly[BSONWriter[Int]].beforeWrite(_.size)
w.writeTry("foo") // Success: BSONInteger(3)
def narrow[U <: T]: BSONWriter[U]

Narrows this writer for a compatible type U.

Narrows this writer for a compatible type U.

import reactivemongo.api.bson.BSONWriter

val listWriter: BSONWriter[Seq[String]] =
 implicitly[BSONWriter[Seq[String]]]

val narrowAsListWriter: BSONWriter[List[String]] =
 listWriter.narrow[List[String]]
 // as List[String] <: Seq[String]

Attributes

U

must be a sub-type of T

Tries to produce a BSON value from an instance of T, returns None if an error occurred.

Tries to produce a BSON value from an instance of T, returns None if an error occurred.

import reactivemongo.api.bson.{ BSONWriter, BSONValue }

def maybeBSON[T](value: T)(implicit w: BSONWriter[T]): Option[BSONValue] =
 w.writeOpt(value)

Attributes