Finally i catch that exception.
first of all:
I try to handle this problem with this annotations :
@Min
@PositiveOrZero
@Pattern(regexp = "\\[0-9]+") or @Pattern(regexp = "\\d+")
@Digits
...
None of them worked, Because that string must first be converted into a number and then validated. so JaxRs could not do that !
I used this solution:
@Provider
public class NumberExceptionMapper implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception exception) {
Exception numberFormatException = getNumberFormatException(exception);
if (numberFormatException != null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Invalid Parameter").build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage()).build();
}
}
private Exception getNumberFormatException(Exception e) {
if (e instanceof NumberFormatException nfe) return nfe;
return getNumberFormatException((Exception) e.getCause());
}
}
Worked without any problem .
Thank you .