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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -