Use type parameter A as static type but use pattern matching to handle
different possible subtypes. This makes it easy to persist algebraic
data types(pattern where you have a sealed trait and several implementing
case classes). When writing a case class into BSON its dynamic type
will be pattern matched, when reading from BSON the pattern matching
will be done on the className string. This option extends
reactivemongo.bson.Macros.Options.SaveClassName in to ensure class
names are always serialized.
If there are handlers available in implicit scope for any of the types
in the union they will be used to handle (de)serialization, otherwise
handlers for all types will be generated.
You can also use case object but you have to refer to their types as to
singleton types. e.g. case object MyObject, type would be MyObject.type
Example
sealedtrait Tree
caseclass Node(left: Tree, right: Tree) extends Tree
caseclass Leaf(data: String) extends Tree
import Macros.Options._
implicitval treeHandler = Macros.handlerOpts[Tree, UnionType[Node \/ Leaf]]
Types
to use in pattern matching. Listed in a "type list" \/
This member is added by an implicit conversion from UnionType[Types] to
any2stringadd[UnionType[Types]] performed by method any2stringadd in scala.Predef.
This member is added by an implicit conversion from UnionType[Types] to
StringFormat[UnionType[Types]] performed by method StringFormat in scala.Predef.
Use type parameter
A
as static type but use pattern matching to handle different possible subtypes. This makes it easy to persist algebraic data types(pattern where you have a sealed trait and several implementing case classes). When writing a case class into BSON its dynamic type will be pattern matched, when reading from BSON the pattern matching will be done on theclassName
string. This option extends reactivemongo.bson.Macros.Options.SaveClassName in to ensure class names are always serialized.If there are handlers available in implicit scope for any of the types in the union they will be used to handle (de)serialization, otherwise handlers for all types will be generated.
You can also use case object but you have to refer to their types as to singleton types. e.g. case object MyObject, type would be MyObject.type
Example
to use in pattern matching. Listed in a "type list" \/