bizzabo / play-json-extensions

+22 field case class formatter and more for play-json
http://cvogt.org/play-json-extensions/api/
Other
196 stars 44 forks source link

formatInline does not catch IllegalArgumentExceptions #48

Open dhoepelman opened 6 years ago

dhoepelman commented 6 years ago

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