play-json-extensions
play-json-extensions copied to clipboard
formatInline does not catch IllegalArgumentExceptions
We've been using this library in combination with require to constrain our domain objects, but still get nice JsErrors back.
Unfortunately this does not work with Jsonx.formatInline
case class PositiveInteger(i: Int) {
require(i >= 1, "Number must be a positive integer")
}
import play.api.libs.json.Json
// JsError(ValidationError("Number must be a positive integer"))
Jsonx.formatCaseClass[PositiveInteger].reads(Json.parse("""{ "i": -1 }""")))
// IllegalArgumentException("Number must be a positive integer") gets thrown
Jsonx.formatInline[PositiveInteger].reads(Json.parse("-1")))
I might be able to create a PR for this friday if this is wanted