I agree that it would be nice to have a secure parse flavor on Json , but its main task is to encode and decode, not serialize and deserialize (if you look at its description of ScalaDoc at the top level, for example, you will see the following: "Helper functions for processing JsValues ββ", not" for processing JSON strings ").
In general, getting from String to JsValue should be closer to the borders of your program, and if you look at how the incoming JSON on Play is processed, you will see that there are safe options (for example, request.body.asJson ).
It would also be useful to play Play to eliminate Jackson exceptions to avoid revealing implementation details, but you definitely don't need to βgetβ to βJacksonβ in any sense to catch these exceptions - just wrap the parse call in Try :
import play.api.libs.json._ import scala.util.Try val parsed: Try[JsValue] = Try(Json.parse("{ broken"))
Or:
val decoded: Option[Map[String, Int]] = Try( Json.parse("""{ "foo": 1 }""") ).toOption.flatMap(_.asOpt[Map[String, Int]])
And so on.
source share