playframework - play scala return two object -
this question has answer here:
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
Post a Comment