playframework - Scala foreach member variable -
is there way loop each member variable of class? it's trivial lists , arrays have construct case class each json field mapping member variable use play framework's reads/validator api
did mean this:
case class someclass(a: int, b: int) someclass(1,2).productiterator.foreach{ => println(a)}
this give output of: 1 2
or if trying construct object json. can define reads in case class deserialises json object :
override def reads(json: jsvalue): jsresult[someclass] = jssuccess(someclass( (json \ "a").as[int], (json \ "b").as[int] ) )
then use deserialisation:
val json = json.obj() //your json json.validate[someclass] json.fold( errors => { json.obj("status" -> "not ok", "message" -> jserror.tojson(errors)) }, preset => { json.obj("status" -> "ok") } )
Comments
Post a Comment