Macros

reactivemongo.api.bson.Macros$
object Macros

Macros for generating BSONReader and BSONWriter at compile time.

import reactivemongo.api.bson.{ BSONDocumentHandler, Macros }

case class Person(name: String, surname: String)

given personHandler: BSONDocumentHandler[Person] = Macros.handler[Person]

Attributes

See also:

MacroOptions for specific options

MacroConfiguration for extended configuration

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Macros.type

Members list

Concise view

Type members

Classlikes

final class Placeholder

Only for internal purposes

Only for internal purposes

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

Only for internal purposes

Only for internal purposes

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final class WithOptions[Opts <: MacroOptions](val config: Aux[Opts])

Macros for generating BSONReader and BSONWriter at compile time, with given options.

Macros for generating BSONReader and BSONWriter at compile time, with given options.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Inherited classlikes

Annotations to use on case classes that are being processed by macros.

Annotations to use on case classes that are being processed by macros.

Attributes

Inherited from:
MacroAnnotations (hidden)
Graph
Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

def configured[Opts <: MacroOptions](implicit config: Aux[Opts]): WithOptions[Opts]

Returns macros using the current BSON configuration.

Returns macros using the current BSON configuration.

Attributes

Opts

the compile-time options

import reactivemongo.api.bson.{
 BSONDocumentReader, MacroConfiguration, Macros
}
case class Foo(name: String)
// Materializes a `BSONDocumentReader[Foo]`,
// with the configuration resolved at compile time
val r1: BSONDocumentReader[Foo] = Macros.configured.reader[Foo]
val r2: BSONDocumentReader[Foo] = Macros.configured(
 MacroConfiguration.simpleTypeName).reader[Foo]
inline def handler[A]: BSONDocumentHandler[A]

Creates a BSONDocumentHandler for type A. The default MacroConfiguration is used (see Macros.configured).

Creates a BSONDocumentHandler for type A. The default MacroConfiguration is used (see Macros.configured).

import reactivemongo.api.bson.{ BSONDocumentHandler, Macros }

case class Foo(bar: String, lorem: Int)

val handler: BSONDocumentHandler[Foo] = Macros.handler

Attributes

A

the type of the value represented as BSON

inline def handlerOpts[A, Opts <: Default]: BSONDocumentHandler[A]

Creates a BSONDocumentHandler for type A. The default MacroConfiguration is used (see Macros.configured), with given additional options.

Creates a BSONDocumentHandler for type A. The default MacroConfiguration is used (see Macros.configured), with given additional options.

import reactivemongo.api.bson.{ Macros, MacroOptions }

case class Foo(bar: String, lorem: Int)

val handler = Macros.handlerOpts[Foo, MacroOptions.Default]

Attributes

A

the type of the value represented as BSON

Opts

the compile-time options

inline def reader[A]: BSONDocumentReader[A]

Creates a BSONDocumentReader for type A. The default MacroConfiguration is used (see Macros.configured).

Creates a BSONDocumentReader for type A. The default MacroConfiguration is used (see Macros.configured).

import reactivemongo.api.bson.{ BSONDocumentReader, Macros }

case class Foo(bar: String, lorem: Int)

val reader: BSONDocumentReader[Foo] = Macros.reader

Attributes

A

the type of the value represented as BSON

inline def readerOpts[A, Opts <: Default]: BSONDocumentReader[A]

Creates a BSONDocumentReader for type A. The default MacroConfiguration is used (see Macros.configured), with given additional options.

Creates a BSONDocumentReader for type A. The default MacroConfiguration is used (see Macros.configured), with given additional options.

import reactivemongo.api.bson.{ Macros, MacroOptions }

case class Foo(bar: String, lorem: Int)

val reader = Macros.readerOpts[Foo, MacroOptions.Verbose]

Attributes

A

the type of the value represented as BSON

Opts

the compile-time options

def using[Opts <: MacroOptions]: WithOptions[Opts]

Returns an inference context to call the BSON macros, using explicit compile-time options.

Returns an inference context to call the BSON macros, using explicit compile-time options.

Attributes

Opts

the compile-time options

import reactivemongo.api.bson.{ BSONDocumentWriter, Macros, MacroOptions }
case class Bar(score: Float)
val w: BSONDocumentWriter[Bar] =
 Macros.using[MacroOptions.Default].writer[Bar]
inline def valueHandler[A <: AnyVal]: BSONHandler[A]

Creates a BSONHandler for Value Class A.

Creates a BSONHandler for Value Class A.

The inner value will be directly write from BSON value.

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

final class FooVal(val v: Int) extends AnyVal // Value Class

val vreader: BSONReader[FooVal] = Macros.valueReader[FooVal]
val vwriter: BSONWriter[FooVal] = Macros.valueWriter[FooVal]

vreader.readTry(BSONInteger(1)) // Success(FooVal(1))

vwriter.writeTry(new FooVal(1)) // Success(BSONInteger(1))

Attributes

Creates a BSONHandler for an opaque type alias A, that itself aliases a Value Class.

Creates a BSONHandler for an opaque type alias A, that itself aliases a Value Class.

The inner value will be directly written as BSON value.

object Types:
 opaque type Logarithm = Double

 object Logarithm {
   def apply(value: Double): Logarithm = value
 }
end Types

object Usage:
 import reactivemongo.api.bson.{ BSONDouble, BSONHandler, Macros }
 import Types.Logarithm

 val vhandler: BSONHandler[Logarithm] = Macros.valueHandler[Logarithm]

 vhandler.readTry(BSONDouble(1.2)) // Success(Logarithm(1.2D))
 vhandler.writeTry(Logarithm(2.34D)) // Success(BSONDouble(2.34D))
end Usage

Attributes

inline def valueReader[A <: AnyVal]: BSONReader[A]

Creates a BSONReader for Value Class A.

Creates a BSONReader for Value Class A.

The inner value will be directly read from BSON value.

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

final class FooVal(val v: Int) extends AnyVal // Value Class

val vreader: BSONReader[FooVal] = Macros.valueReader[FooVal]

vreader.readTry(BSONInteger(1)) // Success(FooVal(1))

Attributes

inline def valueReader[A : OpaqueAlias]: BSONReader[A]

Creates a BSONReader for an opaque type alias A, that itself aliases a Value Class.

Creates a BSONReader for an opaque type alias A, that itself aliases a Value Class.

The inner value will be directly written as BSON value.

object Types:
 opaque type Logarithm = Double

 object Logarithm {
   def apply(value: Double): Logarithm = value
 }
end Types

object Usage:
 import reactivemongo.api.bson.{ BSONDouble, BSONReader, Macros }
 import Types.Logarithm

 val vreader: BSONReader[Logarithm] = Macros.valueReader[Logarithm]

 vreader.readTry(BSONDouble(1.2)) // Success(Logarithm(1.2D))
end Usage

Attributes

inline def valueWriter[A <: AnyVal]: BSONWriter[A]

Creates a BSONWriter for Value Class A.

Creates a BSONWriter for Value Class A.

The inner value will be directly writen from BSON value.

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

final class FooVal(val v: Int) extends AnyVal // Value Class

val vwriter: BSONWriter[FooVal] = Macros.valueWriter[FooVal]

vwriter.writeTry(new FooVal(1)) // Success(BSONInteger(1))

Attributes

inline def valueWriter[A : OpaqueAlias]: BSONWriter[A]

Creates a BSONWriter for an opaque type alias A, that itself aliases a Value Class.

Creates a BSONWriter for an opaque type alias A, that itself aliases a Value Class.

The inner value will be directly writen from BSON value.

object Types:
 opaque type Logarithm = Double

 object Logarithm {
   def apply(value: Double): Logarithm = value
 }
end Types

object Usage:
 import Types.Logarithm
 import reactivemongo.api.bson.{ BSONWriter, Macros }

 val vwriter: BSONWriter[Logarithm] = Macros.valueWriter[Logarithm]

 vwriter.writeTry(Logarithm(1.2D)) // Success(BSONDouble(1.2))
end Usage

Attributes

inline def writer[A]: BSONDocumentWriter[A]

Creates a BSONDocumentWriter for type A. The default MacroConfiguration is used (see Macros.configured).

Creates a BSONDocumentWriter for type A. The default MacroConfiguration is used (see Macros.configured).

import reactivemongo.api.bson.{ BSONDocumentWriter, Macros }

case class Foo(bar: String, lorem: Int)

val writer: BSONDocumentWriter[Foo] = Macros.writer

Attributes

A

the type of the value represented as BSON

inline def writerOpts[A, Opts <: Default]: BSONDocumentWriter[A]

Creates a BSONDocumentWriter for type A. The default MacroConfiguration is used (see Macros.configured), with given additional options.

Creates a BSONDocumentWriter for type A. The default MacroConfiguration is used (see Macros.configured), with given additional options.

import reactivemongo.api.bson.{ Macros, MacroOptions }

case class Foo(bar: String, lorem: Int)

val writer = Macros.writerOpts[Foo, MacroOptions.DisableWarnings]

Attributes

A

the type of the value represented as BSON

Opts

the compile-time options