Generic DAO with formater

35 views
Skip to first unread message

Nicolas Esteban

unread,
Jan 29, 2016, 10:57:40 AM1/29/16
to ReactiveMongo - http://reactivemongo.org
HI,

I'm trying to implement a generic DAO with find, insert and update methods.
The problem is I don't know what is the json formater of generic class, and this code can't work :

def find(uuid:UUID): Future[Option[A]] =
collection.find(Json.obj("uuid" -> uuid)).one[A]

I got this error :

No Json deserializer found for type A. Try to implement an implicit Reads or Format for this type.
    collection.find(Json.obj("uuid" -> uuid)).one[A]

Is there a trick to do that ? May be Inject a formater ...

Thanks in advance

Cédric Chantepie

unread,
Jan 29, 2016, 6:10:56 PM1/29/16
to ReactiveMongo - http://reactivemongo.org
Hi,

This is not specific to ReactiveMongo.

Your function must be defined as following: def find(uuid:UUID)(implicit r: Reads[A]): Future[Option[A]]

I suggest you first have a look at the Playframework JSON documentation.
Reply all
Reply to author
Forward
0 new messages