Home

Awesome

ReactiveMongo Derived Codecs

BSONDocumentReader and BSONDocumentWriter derivation for algebraic data types (sealed traits and case classes).

Compared to the ReactiveMongo’s macros, this project brings support for:

Installation

Add the following dependency to your build:

libraryDependencies += "org.julienrf" %% "reactivemongo-derived-codecs" % "3.0.0"

Version 3.0.0 is built against Scala 2.11 and 2.12, shapeless 2.3 and ReactiveMongo 0.12.

Usage

See API documentation.

Case classes

import reactivemongo.bson.{derived, BSONDocumentHandler}

case class User(name: String, age: Int)
object User {
  implicit val bsonCodec: BSONDocumentHandler[User] = derived.codec[User]
}

Sealed traits

import reactivemongo.bson.{derived, BSONDocumentHandler}

sealed trait Foo
case class Bar(i: Int, b: Boolean) extends Foo
case class Baz(s: String) extends Foo
object Foo {
  implicit val bsonCodec: BSONDocumentHandler[Foo] = derived.codec[Foo]
}

Changelog

License

This content is released under the MIT License.