Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abhirockzz/f605c2eadd3e8169b163 to your computer and use it in GitHub Desktop.
Save abhirockzz/f605c2eadd3e8169b163 to your computer and use it in GitHub Desktop.
Overriding the default exception mapper supplied by JAX-RS implementations
@Provider
public class BeanValConstrainViolationExceptionMapper implements ExceptionMapper<ConstraintViolationException>{
@Override
public Response toResponse(ConstraintViolationException e) {
System.out.println("BeanValConstrainViolationExceptionMapper in action");
ConstraintViolation cv = (ConstraintViolation) e.getConstraintViolations().toArray()[0];
//oh yeah... you need to shell out some $$$ !
return Response.status(Response.Status.PAYMENT_REQUIRED)
.entity(new ConstraintViolationEntity(cv.getMessage()))
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment