当引用"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23"
时,我有以下代码可在控制台应用程序中使用
当我更新对"org.reactivemongo" % "play2-reactivemongo_2.11" % "0.11.0.play23-M3"
的引用时,我得到:
找不到play.api.libs.json.JsObject类型的Json序列化程序作为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 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"
)。
如updated documentation所示,对于默认的BSON / JSON转换,建议使用:import play.modules.reactivemongo.json._, ImplicitBSONHandlers._
。
关于json - 找不到play.api.libs.json.JsObject类型的Json序列化程序作为JsObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31142366/