没有找到play.api.libs.json.JsObject类型的Json序列化程序作为JsObject [英] No Json serializer as JsObject found for type play.api.libs.json.JsObject

查看:212
本文介绍了没有找到play.api.libs.json.JsObject类型的Json序列化程序作为JsObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在引用"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23"

当我更新对"org.reactivemongo" % "play2-reactivemongo_2.11" % "0.11.0.play23-M3"的引用时,我得到:

when I update the reference to "org.reactivemongo" % "play2-reactivemongo_2.11" % "0.11.0.play23-M3" I get:

没有找到类型为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.

import org.joda.time.DateTime
import reactivemongo.bson.BSONObjectID
import play.modules.reactivemongo.json.BSONFormats._

case class GoogleToken
(
  id: Option[BSONObjectID],
  name: String,
  emailAddress: String,
  refreshToken: String,
  expires: DateTime
  )

object GoogleToken {

  import play.api.libs.json.Json

  // Generates Writes and Reads
  implicit val googleTokenFormat = Json.format[GoogleToken]
}

然后

val collection = db.collectionJSONCollection

val collection = db.collectionJSONCollection

val query = Json.obj()
val cursor = collection.find(query).
  cursor[GoogleToken](ReadPreference.nearest).
  collect[List]()

我在做什么错了?

推荐答案

ReactiveMongo 0.11的最终版本已发布("org.reactivemongo" %% "play2-reactivemongo" % "0.11.0.play23").

The final release of ReactiveMongo 0.11 has been published ("org.reactivemongo" %% "play2-reactivemongo" % "0.11.0.play23").

更新的文档所述,对于默认的BSON/JSON转换,建议使用拥有:import play.modules.reactivemongo.json._, ImplicitBSONHandlers._.

As indicated on the updated documentation, for the default BSON/JSON conversions, it's recommended to have: import play.modules.reactivemongo.json._, ImplicitBSONHandlers._.

这篇关于没有找到play.api.libs.json.JsObject类型的Json序列化程序作为JsObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆