I have put a constraint on a field like so:
import javax.validation.constraints.Pattern;
@Pattern(regexp=SOME_REGEX)
private String someField;
The regex is working correctly, but in the case of an invalid value, the value is getting logged:
[Field error in object 'containingSomeField' on field 'someField': rejected value [InvalidValue123];
Is there a way to disable this logging in annotations? I have not been able to find anything thus far.
I do not want to disable logging in general, just the printing of this value. Masking the value would suffice.
EDIT:
Found the answer to my own question. You can override the default exception handler:
@ControllerAdvice
public class ResponseExceptionHandler extends ResponseEntityExceptionHandler {
@Override
public final ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex,
@NonNull HttpHeaders headers,
@NonNull HttpStatus status,
@NonNull WebRequest request
) {
// Your code here
}
}