Writing complex/nested JSON Writes in Scala PlayFramework -


going assume have 2 case classes: child, parent like:

case class child() case class parent(child: child) 

assume i've implemented writes[child]. i'd implement writes[parent].

i'm able using combinators:

implicit val parentwrites: writes[parent] = (    (__ \ "child").write[child] )(unlift(parent.unapply)) 

but following approach, compiler complains it's seeing type child while expecting jsvaluewrapper:

implicit val parentwrites = new writes[parent] {    def writes(parent: parent) = json.obj(       "child" -> parent.child    ) } 

hoping can me understand how implement writes[parent] without using combinators.

this work me without compile issues.

import play.api.libs.json._  case class child(t: string) case class parent(child: child)  implicit val parentwrites = new writes[parent] {   def writes(parent: parent) = json.obj("child" -> parent.child) } 

if still having trouble, useful if can share complete sample stacktrace.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -