I receive, in my client, a WSResponse, and use play's deserializeJson method to extract the data, specified by paths, e.g.
implicit val lsmf: Format[MyData] = (
(__).formatNullable[JsValue] ~
(__ \ "id").format[Int] ~
(__ \ "name").format[String])
(MyData.apply, unlift(MyData.unapply))
The receiving class will look like
case class MyData(
json: JsValue,
id: Int,
name: String) {...}
See, the first member of parsed data is supposed to contain the whole JSON as received.
I don't see how I can accomplish it. If I specify the path as (__), this is a bad path, and the parser fails. If I specify the path as (__ \ ""), the parser looks for a field named "", which is obviously missing.
Is there any reasonable solution, beyond just doing parsing manually (with my own hands)?
You don't need to do manual mapping if the
fields of your case classhas thesame fields and types of json fields. You can you use directly an implicit val usingJson.writes[A]for serializing,Json.reads[A]for deserializing orJson.format[A]for serialize and deserialize.Here in the official docs shows how to do json automated mapping