BSONReader

reactivemongo.api.bson.BSONReader
See theBSONReader companion trait
object BSONReader

BSONReader factories

Attributes

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

Members list

Value members

Concrete methods

def apply[T](read: BSONValue => T): BSONReader[T]

Creates a BSONReader based on the given read function.

Creates a BSONReader based on the given read function.

import reactivemongo.api.bson.{ BSONReader, BSONInteger }

val intToStrCodeReader = BSONReader[String] {
 case BSONInteger(0) => "zero"
 case BSONInteger(1) => "one"
 case _ => "unknown"
}

intToStrCodeReader.readTry(BSONInteger(0)) // Success("zero")
intToStrCodeReader.readTry(BSONInteger(1)) // Success("one")
intToStrCodeReader.readTry(BSONInteger(2)) // Success("unknown")

Any Exception thrown by the read function will be caught.

Attributes

Creates a BSONReader based on the given partial function.

Creates a BSONReader based on the given partial function.

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

import reactivemongo.api.bson.{ BSONReader, BSONInteger }

val intToStrCodeReader = BSONReader.collect[String] {
 case BSONInteger(0) => "zero"
 case BSONInteger(1) => "one"
}

intToStrCodeReader.readTry(BSONInteger(0)) // Success("zero")
intToStrCodeReader.readTry(BSONInteger(1)) // Success("one")

intToStrCodeReader.readTry(BSONInteger(2))
// => Failure(ValueDoesNotMatchException(..))

intToStrCodeReader.readOpt(BSONInteger(3)) // None (as failed)

Attributes

def from[T](read: BSONValue => Try[T]): BSONReader[T]

Creates a BSONReader based on the given read function.

Creates a BSONReader based on the given read function.

import scala.util.{ Failure, Success }
import reactivemongo.api.bson.{ BSONReader, BSONInteger }

val intToStrCodeReader = BSONReader.from[String] {
 case BSONInteger(0) => Success("zero")
 case BSONInteger(1) => Success("one")
 case _ => Failure(new IllegalArgumentException())
}

intToStrCodeReader.readTry(BSONInteger(0)) // Success("zero")
intToStrCodeReader.readTry(BSONInteger(1)) // Success("one")

intToStrCodeReader.readTry(BSONInteger(2))
// => Failure(IllegalArgumentException(..))

intToStrCodeReader.readOpt(BSONInteger(3)) // None (as failed)

Value parameters

read

the safe function to read BSON values as T

Attributes

def option[T](read: BSONValue => Option[T]): BSONReader[T]

Creates a BSONReader based on the given read function.

Creates a BSONReader based on the given read function.

import reactivemongo.api.bson.{ BSONReader, BSONInteger }

val intToStrCodeReader = BSONReader.option[String] {
 case BSONInteger(0) => Some("zero")
 case BSONInteger(1) => Some("one")
 case _ => None
}

intToStrCodeReader.readTry(BSONInteger(0)) // Success("zero")
intToStrCodeReader.readTry(BSONInteger(1)) // Success("one")

intToStrCodeReader.readTry(BSONInteger(2))
// => Failure(ValueDoesNotMatchException(..))

intToStrCodeReader.readOpt(BSONInteger(3)) // None (as failed)

Attributes

def sequence[T](read: BSONValue => Try[T]): BSONReader[Seq[T]]

'''EXPERIMENTAL:''' (API may change without notice)

'''EXPERIMENTAL:''' (API may change without notice)

Creates a BSONReader accepting only BSONArray, and applying the given safe read function to each element value.

import reactivemongo.api.bson.BSONReader

def foo(elmReader: BSONReader[(String, Int)]): BSONReader[Seq[(String, Int)]] = BSONReader.sequence(elmReader.readTry _)

Attributes

def tuple2[A : BSONReader, B : BSONReader]: BSONReader[(A, B)]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

import reactivemongo.api.bson.{ BSONArray, BSONReader }

val reader = BSONReader.tuple2[String, Int]

val arr = BSONArray("Foo", 20)

reader.readTry(arr) // => Success(("Foo", 20))

Attributes

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

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

Attributes

See also
def tuple4[A : BSONReader, B : BSONReader, C : BSONReader, D : BSONReader]: BSONReader[(A, B, C, D)]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

Attributes

See also
def tuple5[A : BSONReader, B : BSONReader, C : BSONReader, D : BSONReader, E : BSONReader]: BSONReader[(A, B, C, D, E)]

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.

Attributes

See also

Inherited methods

def iterable[T, M[_]](read: BSONValue => Try[T])(implicit cbf: Factory[T, M[T]]): BSONReader[M[T]]

'''EXPERIMENTAL:''' (API may change without notice)

'''EXPERIMENTAL:''' (API may change without notice)

Creates a BSONReader accepting only BSONArray, and applying the given safe read function to each element value.

import reactivemongo.api.bson.BSONReader

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

def elementReader: BSONReader[Element] = ???

val setReader: BSONReader[Set[Element]] =
 BSONReader.iterable[Element, Set](elementReader readTry _)

Attributes

Inherited from:
BSONReaderCompat (hidden)

Givens

Inherited givens

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)
given dateTimeReader: BSONReader[Instant]

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)
given localDateReader: BSONReader[LocalDate]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given localDateTimeReader: BSONReader[LocalDateTime]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given localTimeReader: BSONReader[LocalTime]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given localeReader: BSONReader[Locale]

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)
given mapKeyReader[K, V](using KeyReader[K], BSONReader[V]): BSONDocumentReader[Map[K, V]]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given mapReader[V](using BSONReader[V]): BSONDocumentReader[Map[String, V]]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given offsetDateTimeReader: BSONReader[OffsetDateTime]

Attributes

Inherited from:
BSONReaderInstances (hidden)

Attributes

Inherited from:
BSONReaderInstances (hidden)
given tuple2Reader[A : BSONReader, B : BSONReader]: BSONReader[(A, B)]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given tuple3Reader[A : BSONReader, B : BSONReader, C : BSONReader]: BSONReader[(A, B, C)]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given tuple4Reader[A : BSONReader, B : BSONReader, C : BSONReader, D : BSONReader]: BSONReader[(A, B, C, D)]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given tuple5Reader[A : BSONReader, B : BSONReader, C : BSONReader, D : BSONReader, E : BSONReader]: BSONReader[(A, B, C, D, E)]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given uriReader: BSONReader[URI]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given urlReader: BSONReader[URL]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given uuidReader: BSONReader[UUID]

Attributes

Inherited from:
BSONReaderInstances (hidden)
given zonedDateTimeReader: BSONReader[ZonedDateTime]

Attributes

Inherited from:
BSONReaderInstances (hidden)

Exports

Inherited defined exports

Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
Exported from BSONIdentityHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)
final implicit def collectionReader[M[_], T](implicit f: Factory[T, M[T]], reader: BSONReader[T]): BSONReader[M[T]]
Exported from LowPriority1BSONHandlers

Attributes

Inherited from:
BSONReaderInstances (hidden)