Skip to content

Instantly share code, notes, and snippets.

@martinburger
Last active December 30, 2015 22:38
Show Gist options
  • Save martinburger/7895077 to your computer and use it in GitHub Desktop.
Save martinburger/7895077 to your computer and use it in GitHub Desktop.
package models
import play.api.libs.functional.syntax._
import play.api.libs.json._
import play.api.libs.json.util._
import play.api.libs.json.Reads._
import play.api.data.validation.ValidationError
case class User(meta: Option[String], name: String, email: String)
object User {
def apply(name: String, email: String) = new User(None, name, email)
}
trait UserReadsAndWrites {
val userReads: Reads[User] = (
(__ \ "name").read[String] ~
(__ \ "email").read[String]
)(User)
// val userReads: Reads[User] = (
// (__ \ "name").read[String] ~
// (__ \ "email").read[String]
// )(User.apply _)
// val userReads: Reads[User] = (
// (__ \ "name").read[String] ~
// (__ \ "email").read[String]
// )(User.apply(_: String, _: String))
val userWrites: Writes[User] = (
(__ \ "meta").writeOpt[String] ~
(__ \ "name").write[String] ~
(__ \ "email").write[String]
)(unlift(User.unapply))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment