Created
February 4, 2013 14:32
-
-
Save dsugden/4707027 to your computer and use it in GitHub Desktop.
ArticlePublishedReads
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
implicit object ArticlePublishedReads extends Reads[ArticlePublishedState] { | |
def reads(json: JsValue) = json match { | |
case JsString(cat) => { | |
val res = articlePublishedMappings collectFirst { case (s, a) if cat.equals(s) => JsSuccess(a) } | |
res.getOrElse(JsError(Seq(JsPath() -> Seq(ValidationError("no such category"))))) | |
} | |
case _ => JsError(Seq(JsPath() -> Seq(ValidationError("validate.error.expected.jsnumber")))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment