There are sever questions around this topic. But I couldn't find any solution for this. When we write a custom validator to validate on multiple fields of a class constraintViolation.getPropertyPath() method will not return any value. Suppose I have written a custom class level validator something like this (https://stackoverflow.com/a/2783859/3725760) to validate on two fields like stateDate and enddate(startDate<= endDate). How can I get field names?
EDIT:
Set<ConstraintViolation<T>> constraintViolationSet = validator.validate(object);
for (ConstraintViolation<?> constraintViolation : set) {
stringBuilder.append(constraintViolation.getPropertyPath() + " ");
stringBuilder.append(constraintViolation.getMessage() + ". ");
stringBuilder.append(constraintViolation.getInvalidValue() + " ");
stringBuilder.append("is not allowed");
}