2013-04-01 1 views
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 _) 

을하지만 위에서 언급 한 오류가 발생합니다 : 내 암시 적 쓰기와 읽기.

답변

0

실제로 지금 나는 salat의 최신 버전에서 그것을 발견했습니다. Json은 모델과 json 객체간에 이동하는 데 자동으로 사용됩니다. 전체 부품을 제거했는데 원활하게 작동하지 않습니다.

https://github.com/novus/salat/wiki/JSON