score:0

Accepted answer

email is a Read[String] while you require a Format[String] here. Format is a combination of Read and Write for cases where they are symmetrical. This isn't the case here because validation is only for reading JSON, not for writing it. So you cannot write a single Format.

To get around this, write your Read and Write separately:

implicit val personReads: Reads[Person] = (
  (JsPath  \ "name").read[String] ~ 
  (JsPath  \ "email").readNullable[String](email)
)(Person.apply _)

implicit val personWrites: Writes[Person] = (
  (JsPath \ "name").write[String] ~
  (JsPath \ "email").writeNullable[String]
)(unlift(Person.unapply))

implicit val personFormat: Format[Person] = 
  Format(personReads,personWrites)

Related Query

More Query from same tag