play-json-extensions icon indicating copy to clipboard operation
play-json-extensions copied to clipboard

formatInline does not catch IllegalArgumentExceptions

Open dhoepelman opened this issue 8 years ago • 0 comments

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

dhoepelman avatar Mar 14 '18 13:03 dhoepelman