I'm using play-json to serialize my incoming jsons to case classes, for example from sqs source, or from api calls.
its a very simple class JsonSerialization that I import where I need it:
object JsonSerialization {
implicit val StatusFormat: Format[Status] = EnumFormats.formats(Status)
implicit val PersonFormat: OFormat[Person] = Json.format[Person]
}
but now I wonder, from what I understand in my Dao there needs to be something to serialize my case class to BSON , cause my Dao gets the case class, and when I fetch from something to de-serialize to my case class. I only imported in the Dao:
import reactivemongo.play.json.compat.json2bson.{toDocumentReader, toDocumentWriter}
import serializers.JsonSerialization._
and find and insert works perfectly,
def insert(person: Person): Future[Person] = {
val writeRes: Future[WriteResult] = collection.insert.one(person)
writeRes.onComplete {
case Failure(e) => e.printStackTrace()
case Success(writeResult) =>
logger.info(s"successfully inserted person")
}
writeRes map { _ => person }
}
def find(name: String): Future[Person] = {
collection.find(BSONDocument(
"name" -> name
)).requireOne[Person]
}
can you please tell me what part in charge of what in the Dao? I'm a bit confused
sorry if this a beginner question, but it will be helpful to get short explanation