本文介绍了找不到 Json 序列化程序作为 JsObject 类型为 play.api.libs.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:

找不到 Json 序列化程序作为类型为 play.api.libs.json.JsObject 的 JsObject.尝试为这种类型实现隐式 OWrites 或 OFormat.

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 集合 = 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._.

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

08-24 11:32