Last active
December 30, 2015 22:38
-
-
Save martinburger/7895077 to your computer and use it in GitHub Desktop.
Complete code for https://github.com/playframework/playframework/issues/2148.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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