Guest User

Untitled

a guest
Jul 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. import play.api.libs.functional.syntax._
  2. import play.api.libs.json.{Format, Reads, Writes, _}
  3.  
  4. case class Person(name: String) extends AnyVal
  5.  
  6. object Person {
  7.  
  8. implicit val f1: Format[Person] = implicitly[Format[String]].inmap[Person](Person(_), _.name)
  9.  
  10. implicit val f2: Format[Person] = Format(__.read[String].map(Person(_)), implicitly[Writes[String]].contramap { case Person(v) => v })
  11.  
  12. implicit val r: Reads[Person] = _.validate[String].map(Person(_))
  13. }
Add Comment
Please, Sign In to add comment