I am following the following example https://github.com/leon/play-salat/tree/master/sample . In my data model I have lists and I tried to adopt the model to that.
I get the following compilation errors:
[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) } ~
For the type "Position" I have implicit reads and writes, but how to make it for List[Position] ? My implicit write and read:
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 _)
For the read I followed Create implicit json read for List collection which might be missing from input json , but I get the above mentioned error.