Skip to content

Instantly share code, notes, and snippets.

@dsugden
Created February 4, 2013 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsugden/4707027 to your computer and use it in GitHub Desktop.
Save dsugden/4707027 to your computer and use it in GitHub Desktop.
ArticlePublishedReads
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