简体   繁体   English

找不到类型为play.api.libs.json.JsValue的Json序列化程序作为JsObject

[英]No Json serializer as JsObject found for type play.api.libs.json.JsValue

I'm trying to migrate my project from using play2-reactivemongo version 0.10.5.0.akka23 to using version 0.11.7.play23 . 我正在尝试将我的项目从使用play2-reactivemongo版本0.10.5.0.akka23到使用版本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 : 我尝试引入隐式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. 解决了这个问题,但是我在代码中有很多这样的想法,我希望有一个更简单的解决方案。

Just got bit by this too. 也刚被这个咬住了。 The trick is to remove 诀窍是删除

import play.modules.reactivemongo.json._

and instead use 而是使用

import reactivemongo.play.json._

The play.modules version doesn't provide the identity OWriter. play.modules版本不提供身份OWriter。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有为类型为play.api.libs.json.JsObject的JsObject找到Json序列化程序 - No Json serializer as JsObject found for type play.api.libs.json.JsObject 值键不是play.api.libs.json.JsValue的成员 - value keys is not a member of play.api.libs.json.JsValue 读取的值不是play.api.libs.json.JsValue的成员 - value read is not a member of play.api.libs.json.JsValue 获取play.api.libs.json.JsValue的所有键 - get all keys of play.api.libs.json.JsValue 找不到play.api.libs.json.JsObject类型的Json序列化程序作为JsObject。 尝试为此类型实现隐式OWrites或OFormat - No Json serializer as JsObject found for type play.api.libs.json.JsObject. Try to implement an implicit OWrites or OFormat for this type 如何将play.api.libs.json.JsValue转换为org.json.JSONObject - how to convert play.api.libs.json.JsValue to org.json.JSONObject 如何在 play.api.libs.json.JsValue 和 org.json4s.JValue 之间进行转换 - How can I convert between play.api.libs.json.JsValue and org.json4s.JValue Scala和Play2:ClassCastException:无法将java.lang.Object强制转换为play.api.libs.json.JsValue - Scala and Play2: ClassCastException: java.lang.Object cannot be cast to play.api.libs.json.JsValue 没有找到类型为reactmongo.play.json.JSONSerializationPack.type的Json序列化程序作为JsObject - No Json serializer as JsObject found for type reactivemongo.play.json.JSONSerializationPack.type Can't unquote play.api.libs.json.JsObject, consider providing an implicit instance of Liftable[play.api.libs.json.JsObject] - Can't unquote play.api.libs.json.JsObject, consider providing an implicit instance of Liftable[play.api.libs.json.JsObject]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM