Wildfly 21 – how to customize returns for Bean Validation exceptions

140 views Asked by At

I've tried registering custom exception mappers in multiple ways:

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ConstraintViolationException> {
    @Override
    public Response toResponse(ConstraintViolationException exception) {
        ...
    }
}

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ResteasyViolationException> {
    @Override
    public Response toResponse(ResteasyViolationException exception) {
        ...
    }
}

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ValidationException> {
    @Override
    public Response toResponse(ValidationException exception) {
        ...
    }
}

But all that happens is the default behaviour by the ResteasyViolationExceptionMapper. My custom ExceptionMapper is never called. I don't know what else to try.

1

There are 1 answers

0
ftr On BEST ANSWER

I don't know why it didn't work when I first tried it, but this works

@Provider
public class ConstraintViolationMapper implements ExceptionMapper<ValidationException> {
    @Override
    public Response toResponse(ValidationException exception) {
        ...
    }
}