How to define implicit Play ReactiveMongo handler for type parameter?

104 Views Asked by At

I'm new to scala and using play2.5 + play2-reactivemongo 0.12.3. now trying to create a base DAO trait as below.

trait BaseDAO[T] {
  val collectionName: String
  def reactiveMongoApi: ReactiveMongoApi
  lazy val collection = reactiveMongoApi.database.map(_.collection(collectionName))

  def findOne(query: JsObject = Json.obj())(implicit reader: Reads[T]): 
    Future[Option[T]] = {
    collection.flatMap(_.find(query).one[T])
  }
}

And I get an error message as following.

could not find implicit value for parameter reader: reactivemongo.bson.BSONDocumentReader[T]
collection.flatMap(_.find(query).one[T])
                                    ^

In case of type parameter, is there any way to solve the error?

0

There are 0 best solutions below