BSONReader specialized for BSONDocument
- Companion:
- object
Value members
Abstract methods
Tries to produce an instance of T
from the document
.
Tries to produce an instance of T
from the document
.
import scala.util.Try
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentReader }
def fromBSON[T](document: BSONDocument)(
implicit r: BSONDocumentReader[T]): Try[T] = r.readTry(document)
Concrete methods
Inherited methods
Prepares a BSONReader that transforms the input BSON value, using the given f
function, before passing the transformed BSON value to the current reader.
Prepares a BSONReader that transforms the input BSON value, using the given f
function, before passing the transformed BSON value to the current reader.
import reactivemongo.api.bson.{
BSONReader, BSONInteger, BSONNull, BSONString
}
val normalizingReader: BSONReader[Int] =
implicitly[BSONReader[Int]].beforeRead {
case BSONNull => BSONInteger(-1)
case BSONString(s) => BSONInteger(s.size)
// other values are unchanged
}
normalizingReader.readOpt(BSONNull) // Some(-1)
normalizingReader.readTry(BSONString("foo")) // Success(3)
normalizingReader.readOpt(BSONInteger(4)) // unchanged: Some(4)
- Inherited from:
- BSONReader
Prepares a BSONReader that transforms the input BSON value, using the given f
function, before passing the transformed BSON value to the current reader.
Prepares a BSONReader that transforms the input BSON value, using the given f
function, before passing the transformed BSON value to the current reader.
- Inherited from:
- BSONReader
Tries to produce an instance of T
from the bson
value,
returns None
if an error occurred.
Tries to produce an instance of T
from the bson
value,
returns None
if an error occurred.
import reactivemongo.api.bson.{ BSONReader, BSONValue }
def fromBSON[T](bson: BSONValue)(implicit r: BSONReader[T]): Option[T] =
r.readOpt(bson)
- Inherited from:
- BSONReader
Tries to produce an instance of T
from the bson
value,
returns the default
value if an error occurred.
Tries to produce an instance of T
from the bson
value,
returns the default
value if an error occurred.
import reactivemongo.api.bson.{ BSONReader, BSONValue }
def fromBSON[T](bson: BSONValue, v: T)(implicit r: BSONReader[T]): T =
r.readOrElse(bson, v)
- Inherited from:
- BSONReader