I have this code
import javax.validation.ValidationException;
/**
* Exception handler for validation exceptions.
* Handles exceptions related to validation data, such as validation errors.
* Returns a ResponseEntity with the appropriate error code, message, and HTTP
* status code 400 (Bad Request).
*/
@ExceptionHandler(ValidationException.class)
public ResponseEntity<ApiError> handleValidationException(ValidationException exception) {
return buildResponseEntity(ErrorCodes.INVALID_NUMBER,
"The number must be a whole number between 0 & " + Long.MAX_VALUE, null,
HttpStatus.BAD_REQUEST);
}
I would like the message to include the name of the field that is not a number the end result shoud be something like this "The number must be a whole number between 0 & " + Long.MAX_VALUE + " for the field " + NAME_OF_FIELD How can i do this in java.
jakarta.validation.ValidationException
? Then you should state this in the question and also add an appropriate tag to the question.