BSONWriter

reactivemongo.api.bson.BSONWriter
See theBSONWriter companion trait
object BSONWriter

BSONWriter factories.

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
BSONWriter.type

Members list

Type members

Inherited types

type SafeWriter[T] = BSONWriter[T] & SafeBSONWriter[T]

Attributes

Inherited from:
BSONWriterInstances (hidden)

Value members

Concrete methods

def apply[T](write: T => BSONValue): BSONWriter[T]

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

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 => BSONString(f.value) }

Attributes

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)

Attributes

'''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)

Attributes

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)

Value parameters

write

the safe function to write T values as BSON

Attributes

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)

Attributes

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

case class Element(str: String, v: Int)

def elementWriter: BSONWriter[Element] = ???

val seqWriter: BSONWriter[Seq[Element]] =
 BSONWriter.sequence[Element](elementWriter writeTry _)

Attributes

def tuple2[A : BSONWriter, B : BSONWriter]: 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]

Attributes

def tuple3[A : BSONWriter, B : BSONWriter, C : BSONWriter]: BSONWriter[(A, B, C)]

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

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

Attributes

def tuple4[A : BSONWriter, B : BSONWriter, C : BSONWriter, D : BSONWriter]: BSONWriter[(A, B, C, D)]

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

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

Attributes

def tuple5[A : BSONWriter, B : BSONWriter, C : BSONWriter, D : BSONWriter, E : BSONWriter]: BSONWriter[(A, B, C, D, E)]

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

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

Attributes

Inherited methods

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

case class Element(str: String, v: Int)

def elementWriter: BSONWriter[Element] = ???

val setWriter: BSONWriter[Set[Element]] =
 BSONWriter.iterable[Element, Set](elementWriter writeTry _)

Attributes

Inherited from:
BSONWriterCompat (hidden)

Givens

Inherited givens

given binaryWriter: SafeWriter[Array[Byte]]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given booleanWriter: SafeWriter[Boolean]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given bsonMapKeyWriter[K, V <: BSONValue](using KeyWriter[K]): BSONDocumentWriter[Map[K, V]]

Attributes

Inherited from:
BSONWriterInstances (hidden)

Attributes

Inherited from:
BSONWriterInstances (hidden)

Attributes

Inherited from:
BSONWriterInstancesLowPrio (hidden)
given dateTimeWriter: SafeWriter[Instant]

Attributes

Inherited from:
BSONWriterInstances (hidden)

Attributes

Inherited from:
BSONWriterInstances (hidden)
given doubleWriter: SafeWriter[Double]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given floatWriter: SafeWriter[Float]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given intWriter: SafeWriter[Int]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given localDateTimeWriter: BSONWriter[LocalDateTime]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given localDateWriter: BSONWriter[LocalDate]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given localTimeWriter: SafeWriter[LocalTime]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given localeWriter: SafeWriter[Locale]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given longWriter: SafeWriter[Long]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given mapKeySafeWriter[K, V](using KeyWriter[K] & SafeKeyWriter[K], BSONWriter[V] & SafeBSONWriter[V]): BSONDocumentWriter[Map[K, V]]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given mapKeyWriter[K, V](using KeyWriter[K], BSONWriter[V]): BSONDocumentWriter[Map[K, V]]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given mapSafeWriter[V](using BSONWriter[V] & SafeBSONWriter[V]): BSONDocumentWriter[Map[String, V]]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given mapWriter[V](using BSONWriter[V]): BSONDocumentWriter[Map[String, V]]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given offsetDateTimeWriter: BSONWriter[OffsetDateTime]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given stringWriter: SafeWriter[String]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given tuple2Writer[A : BSONWriter, B : BSONWriter]: BSONWriter[(A, B)]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given tuple3Writer[A : BSONWriter, B : BSONWriter, C : BSONWriter]: BSONWriter[(A, B, C)]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given tuple4Writer[A : BSONWriter, B : BSONWriter, C : BSONWriter, D : BSONWriter]: BSONWriter[(A, B, C, D)]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given tuple5Writer[A : BSONWriter, B : BSONWriter, C : BSONWriter, D : BSONWriter, E : BSONWriter]: BSONWriter[(A, B, C, D, E)]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given uriWriter: SafeWriter[URI]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given urlWriter: SafeWriter[URL]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given uuidWriter: SafeWriter[UUID]

Attributes

Inherited from:
BSONWriterInstances (hidden)
given zonedDateTimeWriter: BSONWriter[ZonedDateTime]

Attributes

Inherited from:
BSONWriterInstances (hidden)

Exports

Inherited defined exports

Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)
export collectionWriter[T, Repr <: Iterable[T]](using BSONWriter[T], Repr ¬ Option[T])
Exported from LowPriority1BSONHandlers

Attributes

Inherited from:
BSONWriterInstances (hidden)