playframework - play scala return two object -


is there wey return both yields?

val process =   {     processtemplate <- processtemplatedto.getprocesstemplate(processtemplateid)     processsteps <- processtemplatedto.getprocesssteptemplates(processtemplateid)   } yield (processtemplate, processsteps)   process.map(p => ok(json.tojson(p))) 

i got error:

no json serializer found type (option[models.processtemplatesmodel], seq[models.processsteptemplatesmodel]). try implement implicit writes or format type. 

you trying write 2-tuple (x,y) json. default there no writes available tuple i.e play framework doesn't know how convert json.

you can fix providing writes,

implicit val writes =  new writes[(a, b)] {      override def writes(o: (a, b)): jsvalue =       json.obj("field1"-> json.tojson(o._1), "filed2" -> json.tojson(o._2)) } 

also need provide writes implementation processtemplatesmodel , processsteptemplatesmodel. can read more json support in play framework on here.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -