BSONReader factories
Attributes
- Companion:
- trait
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
- Self type
- BSONReader.type
Members list
Value members
Concrete methods
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
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)
Attributes
- read
the safe function to read BSON values as
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
'''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
'''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
'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.
'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.
Attributes
- See also:
'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.
'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.
Attributes
- See also:
'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.
'''EXPERIMENTAL:''' Creates a BSONDocumentReader that reads the BSONArray elements.
Attributes
- See also:
Inherited methods
'''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)
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)
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)
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)
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)
Attributes
- Inherited from:
- BSONReaderInstances (hidden)
Attributes
- Inherited from:
- BSONReaderInstances (hidden)
Exports
Inherited defined exports
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)
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)
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)
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)
Attributes
- Inherited from:
- BSONReaderInstances (hidden)