Let's say I have to write custom Reads[Person]
for Person
class:
import play.api.libs.functional.syntax._
implicit val personReads: Reads[Person] = (
(__ \ "name").read[String] and // or ~
(__ \ "age").readNullable[Int]
) ((name, age) => Person(name = name, age = age))
it works like a charm, really (no).
But what can I do when there is only one field in json object?
The core of Reads
and Writes
is in functional syntax which transforms these "parse" steps.
The following does not compile:
import play.api.libs.functional.syntax._
implicit val personReads: Reads[Person] = (
(__ \ "name").read[String]
)(name => Person(name))
Could you advice how to deal with it?