I'm trying to migrate my project from using play2-reactivemongo
version 0.10.5.0.akka23
to using version 0.11.7.play23
. I've already added the following import to fix the problems addressed in this question:
import play.modules.reactivemongo.json._
With the former version, the following code worked:
val updateEntity = Json.obj("_id" -> Json.obj("$oid" -> id))
val entity = Json.parse(stringJson)
collection.update(updateEntity, entity)
however, using the new version, the third line gives a compile error:
[error] No Json serializer as JsObject found for type play.api.libs.json.JsValue. Try to implement an implicit OWrites or OFormat for this type.
[error] collection.update(updateEntity, entity)
[error] ^
I've tried introducing an implicit OWriter
:
implicit val toJsObject: OWrites[JsValue] = OWrites.apply(_.as[JsObject])
but that gives an implicit declaration conflict:
[error] ambiguous implicit values:
[error] both value toJsObject of type play.api.libs.json.OWrites[play.api.libs.json.JsValue]
[error] and object JsObjectDocumentWriter in trait ImplicitBSONHandlers of type play.modules.reactivemongo.json.JsObjectDocumentWriter.type
[error] match expected type collection.pack.Writer[play.api.libs.json.JsObject]
[error] collection.update(updateEntity, entity)
[error] ^
changing the second line to
val entity = Json.parse(stringJson).as[JsObject]
fixes the problem, but I have a lot of these around my code and I was hoping for a simpler solution.