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.

  1. you may return ok(json.tojson(xs))
  2. you may explicitly point desired type: ok(xs: jsvalue)

and sure implicits in scope


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -