scala - Play 2 - Can't return Json object in Response -
i'm trying restfull web service poc using play 2.1.3
i have following class:
case class student(id: long,firstname: string,lastname: string) now create restfull uri json serialised student pojo , return same pojo in response.
implicit val studentreads = json.reads[student] implicit val studentwrites = json.writes[student] def updatestudent = action(parse.json){ request=>request.body.validate[student].map{ case xs=>ok(xs)}.recovertotal{ e => badrequest("detected error:"+ jserror.toflatjson(e)) } } but i'm getting compilation error -
cannot write instance of entities.student http response. try define writeable[entities.student] i provided writes[a] implicit variable.
what else missing?
i think problem ok() method cannot figure out student needs transformed json, arguments ok() may vary.
- you may return
ok(json.tojson(xs)) - you may explicitly point desired type:
ok(xs: jsvalue)
and sure implicits in scope
Comments
Post a Comment