this problem has me crazy and I don't know where to look anymore.
I have a rest api that receives a @RequestBody DTO
public ResponseEntity<JuntaCalificadoraDTO> edit(@Valid @RequestBody JuntaCalificadoraDTO juntaCalifDTO) {
......
This is the DTO that I receive and that I validate with java bean validations. Generate getter and setters with lombok
@Data
@NoArgsConstructor
public class JuntaCalificadoraDTO extends RepresentationModel<JuntaCalificadoraDTO> {
private Long id_process;
@NotNull @Min(1) @Positive
private Integer presidentJC;
@NotNull @Min(1) @Positive
private Integer secretaryJC;
@NotNull @Min(1) @Positive
private Integer representativeFuncJC;
}
Java bean validations does its job. It is valid that it is not zero, its minimum and also that it is positive. The problem is that it does not validate when I pass a letter to a variable, for example:
{
"id_process": 4455,
"presidentJC": "dd",
"secretaryJC": 33,
"representativeFuncJC": 3
}
It detects the error, and postman returns "400 Bad Request" but nothing else. Also the Intellij console doesn't show anything, no stack.
I need to catch that error which I imagine is a "NumberFormatException" but I haven't been able to. And I don't know why he hides it. I created a method in a @ControllerAdvice class but no success either.
@ExceptionHandler (value = {NumberFormatException.class})
public final ResponseEntity<Object> invalidNumberHandling(NumberFormatException ex) {
ApiError apiError = ApiError.builder()
.timestamp(LocalDateTime.now())
.status(HttpStatus.BAD_REQUEST)
.message("Number Format Exception")
.errors(List.of("El o los parámetros de entrada no son válidos"))
.details(ex.getMessage())
.build();
return new ResponseEntity<>(apiError, apiError.getStatus());
}
I will appreciate any guidance. And sorry for my bad english