1

次の例に従っています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) } ~

タイプ「Position」の場合、暗黙的な読み取りと書き込みがありますが、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 _)

読み取りについては、入力 json から欠落している可能性がある List コレクションの Create implicit json readに従いましたが、上記のエラーが発生します。

4

1 に答える 1