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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -