Last active
August 29, 2015 14:09
-
-
Save dgouyette/814dd4da109c6355d2a8 to your computer and use it in GitHub Desktop.
filterTransform
This file contains hidden or 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
val objTransformer = | |
(__ \ "_embedded" \ "contract").json.copyFrom( | |
(__ \ "contract").readNullable[JsArray].map(_.getOrElse(JsArray())) | |
) and | |
(__ \ "_embedded" \ "comment").json.copyFrom( | |
(__ \ "comment").readNullable[Comment].filter(reviewOpt => isApproved(reviewOpt)) | |
) | |
(__ \ "title").readNullable[String].map(_.fold(JsObject(Nil))(s => Json.obj("title" -> s))) | |
def isApproved(commentOpt : Option[Comment]) = { | |
(for { | |
comment <- commentOpt | |
status <- comment.status | |
} yield { | |
status==Status.approved | |
}).getOrElse(false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mais ça ne marche pas avec le
orElse
?