通用scala json解析器框架2
我在Scala中使用play2.1.1,并尝试编写[IndexResults[T]],在这里可以找到IndexResults[T]的定义 我的代码:通用scala json解析器框架2,json,parsing,scala,playframework-2.1,writer,Json,Parsing,Scala,Playframework 2.1,Writer,我在Scala中使用play2.1.1,并尝试编写[IndexResults[T]],在这里可以找到IndexResults[T]的定义 我的代码: import com.github.cleverage.elasticsearch.ScalaHelpers._ import com.github.cleverage.elasticsearch._ // used for others stuffs ... val writeResults: Writes[ScalaHelpers.Inde
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) ^
重载方法值写入选项:
[error](t:List[t])(隐式w:play.api.libs.json.Writes[List[t]])play.api.libs.json.OWrites[play.api.libs.json.JsValue]
[error](隐式w:play.api.libs.json.Writes[List[T]])play.api.libs.json.OWrites[List[T]]
[错误]无法应用于(play.api.libs.json.Writes[T])
[错误](“结果”)。写入[列表[T]](写入)^
我不明白为什么它不起作用,这个错误对我来说没有任何意义。拥有通用scala json编写器的正确方法是什么?我应该如何使用它
附:官方文件对我帮助不大
谢谢你是什么阻止你使用Json.toJson?因为我不想要所有字段。你不需要创建每个字段。看看,你是说“Json.toJson(IndexResults[User])”吗?