In one of my projects I've already upgraded Jersey from version 2.14
to 2.23
. But I'm struggling many hours with one problem. My project defines its own ExceptionMapper
for a ValidationException
, but unfortunately Jersey already has a built-in exception mapper for this exception and I cannot override it.
I have registered correctly (I checked it) my own mapper which is presented below:
@Provider
public class ValidationExceptionMapper implements
ExceptionMapper<ValidationException> {
@Override
public Response toResponse(ValidationException exception) {
return Response.status(Status.BAD_REQUEST).build();
}
}
but it is never being called. Jersey always pick up the org.glassfish.jersey.server.validation.internal.ValidationExceptionMapper
.
I've also tried to use @Priority
annotation for my custom mapper, but unfortunately Jersey doesn't take it into account.
So what is going on? It worked perfectly fine in the previous Jersey version, so it seems to be a regression bug.
I give up. Any clues?
ConstraintViolationException
(which is the actual type of the validation exceptions) as a work around. It is more specific thanValidationException
, so it will take precedence. I never figured out how to disable that one mapper, without disabling all meta-inf providers (not a fun solution). My work around was to simply use a mapper forConstraintViolationException
– LourValidationException
s. – MauriciomaurieConstraintViolationException
extendsValidationException
. The exception type thrown with the bean validation in Jersey will always be aConstraintViolationException
. It works forValidationException
, because super type mappers can handle sub-type exceptions, is there is no mapper for the sub-type – Lour