Json Validation with PlayFramework in Scala -
Json Validation with PlayFramework in Scala -
can please help me prepare next code:
case class person(name:string,email:option[string]) implicit val personformat:format[person] = ( (__ \ "name").format[string] ~ (__ \ "email").formatnullable[string](email) // code doesn't compile here )(person.apply,unlift(person.unapply))
apparently formatnullable doesn't work readconstraints, how can resolve ?
email
read[string]
while require format[string]
here. format
combination of read
, write
cases symmetrical. isn't case here because validation reading json, not writing it. cannot write single format
.
to around this, write read
, 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)
scala playframework playframework-2.3
Comments
Post a Comment