我正在关注以下示例https://github.com/leon/play-salat/tree/master/sample。在我的数据模型中,我有列表,我尝试采用该模型。
我收到以下编译错误:
[error] /home/malte/workspace/bdt/app/models/Ballot.scala:26: No Json deserializer found        for type List[models.Position]. Try to implement an implicit Writes or Format for this type.
[error]         "positions" -> b.positions,
[error]                          ^
[error] /home/malte/workspace/bdt/app/models/Ballot.scala:33: No Json deserializer found for type List[models.Position]. Try to implement an implicit Reads or Format for this type.
[error]       (__ \ 'values).read[List[Position]]).map { l => l.getOrElse(Nil) } ~
对于“位置”类型,我有隐式读写,但是如何为 List[Position] 制作它?我的隐式读写:
implicit val ballotJsonWrite = new Writes[Ballot] {
  def writes(b: Ballot): JsValue = {
    Json.obj(
      "positions" -> b.positions,
      "title" -> b.title)
  }
}
implicit val ballotJsonRead = (
(__ \ 'positions).readNullable(
  (__ \ 'values).read[List[Position]]).map { l => l.getOrElse(Nil) } ~
  (__ \ 'title).read[String])(Ballot.apply _)
对于我遵循的为 List 集合创建隐式 json 读取的读取,输入 json 中可能缺少该读取,但我得到了上述错误。