通用scala json解析器playframework 2

时间:2013-07-10 22:17:54

标签: json parsing scala playframework-2.1 writer

我在Scala中使用play2.1.1并且我正在尝试创建一个Writes [IndexResults [T]],其中IndexResults [T]的定义可以在file的末尾找到。< / p>

我的代码:

import com.github.cleverage.elasticsearch.ScalaHelpers._
import com.github.cleverage.elasticsearch._ // used for others stuffs

...

val writeResults: Writes[ScalaHelpers.IndexResults[T]] = (
  (__ \ "totalCount").write[Long] and
  (__ \ "pageSize").write[Long] and
  (__ \ "pageCurrent").write[Long] and
  (__ \ "pageNb").write[Long] and
  (__ \ "results").write[List[T]](writes)
)(unlift(ScalaHelpers.IndexResults[T].unapply))

我的错误:

overloaded method value write with alternatives:
[error]   (t: List[T])(implicit w: play.api.libs.json.Writes[List[T]])play.api.libs.json.OWrites[play.api.libs.json.JsValue] <and>
[error]   (implicit w: play.api.libs.json.Writes[List[T]])play.api.libs.json.OWrites[List[T]]
[error]  cannot be applied to (play.api.libs.json.Writes[T])
[error]     (__ \ "results").write[List[T]](writes)                                ^

我无法弄清楚为什么它不起作用而且错误对我来说没有任何意义。拥有通用scala json writer的正确方法是什么以及我应该如何使用它?

PS:官方文档对我没那么帮助。

谢谢

0 个答案:

没有答案