Bean Validation is a good option to validate objects, but how to customize the response of a REST API (using RESTeasy) when a ConstraintViolationException
is thrown?
For example:
@POST
@Path("company")
@Consumes("application/json")
public void saveCompany(@Valid Company company) {
...
}
A request with invalid data will return a HTTP 400
status code with the following body:
[PARAMETER]
[saveCompany.arg0.name]
[{company.name.size}]
[a]
It's nice but not enough, I would like to normalize these kind of errors in a JSON document.
How can I customize this behavior?