我有一个这样的案例类
case class Wish(_id: Option[String], title : String, text :String, cash: Int, created_at: Option[DateTime], updated_at : Option[DateTime])
我还定义了一个隐式读取验证器,如下所示
implicit val wishFormat = Json.format[Wish]
我正在尝试将 Mongodb 文档读入我的愿望类,但出现如下错误
scala> val js = "{\"_id\":{\"$oid\":\"5259c384dd8251bb085adfb4\"},\"title\":\"Shrikar\",\"text\":\"test\",\"cash\":12.0,\"created_at\":1381614468235,\"updated_at\":1381614468235}"
js: String = {"_id":{"$oid":"5259c384dd8251bb085adfb4"},"title":"Shrikar","text":"test","cash":12.0,"created_at":1381614468235,"updated_at":1381614468235}
scala> val test = Json.parse(js)
test: play.api.libs.json.JsValue = {"_id":{"$oid":"5259c384dd8251bb085adfb4"},"title":"Shrikar","text":"test","cash":12.0,"created_at":1381614468235,"updated_at":1381614468235}
scala> test.validate[Wish]
res11: play.api.libs.json.JsResult[Wish] = JsError(List((/_id,List(ValidationError(validate.error.expected.jsstring,WrappedArray())))))
你能帮我解决这个问题吗?