1
다음 예제는 다음과 같습니다. https://github.com/leon/play-salat/tree/master/sample. 내 데이터 모델에는 목록이 있고 그 모델을 채택하려고했습니다. 나는 다음과 같은 컴파일 오류가 얻을목록에 대한 암시 적 json 읽기 및 쓰기
: 나는 암시 유형 "위치"를
[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) } ~
가 읽기 및 쓰기,하지만 어떻게 [위치] 목록을 위해 그것을하기 위해? 내가 Create implicit json read for List collection which might be missing from input json을 따라 읽기에 대한
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 _)
을하지만 위에서 언급 한 오류가 발생합니다 : 내 암시 적 쓰기와 읽기.