Last active
December 29, 2015 16:29
-
-
Save danielkhan/7698131 to your computer and use it in GitHub Desktop.
Sanitizing Json data in Scala Play
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
implicit val transformFormat: Reads[JsObject] = { | |
(__ \ 'situation).json.update(of[JsString].map { | |
case JsString(situation) => JsString(Sanitizer.toMarkDown(situation)) | |
}) andThen | |
(__ \ 'solution).json.update(of[JsString].map { | |
case JsString(solution) => JsString(Sanitizer.toMarkDown(solution)) | |
}) andThen | |
(__ \ 'name).json.update(of[JsString].map { | |
case JsString(raw) => JsString(Sanitizer.toText(raw)) | |
}) andThen | |
(__ \ 'company).json.update(of[JsString].map { | |
case JsString(raw) => JsString(Sanitizer.toText(raw)) | |
}) andThen | |
(__ \ 'tags).json.update( | |
__.read[JsArray].map { | |
tags => JsArray(tags.as[List[String]].map { | |
tag => JsString(Sanitizer.toText(tag)) | |
}) | |
}.orElse(Reads.pure(new JsArray))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment