In short I'm dealing with JSON that has to look like:
{
"data": JSON.stringify(...), // eg. JSON.stringify(null) or JSON.stringify({p: "v"})
...
}
I wish to parse it into a case class resembling something like:
case class Foo(data: JsObject, ...)
And the Reads[Food] I've defined looks like this:
val fooReads: Reads[Foo] = (
(__ \"data").readNullable[String].map(_.filter(s => s != null && !s.isEmpty).map(Json.parse(_).as[JsObject]).getOrElse(JsObject(Seq()))),
...
)
But I keep getting the following error:
ValidationError(error.expected.jsobject,WrappedArray())
I'm pretty sure my Reads[Foo] is now resembling an ugly tumor that doesn't need to exist, so some help would be nice.