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

python - Best design pattern for collection of objects -

go - serving up pdfs using golang -

python - django admin: changing the way a field (w/ relationship to another model) is submitted on a form so that it can be submitted multiple times -