ConstraintViolation methods
2.2.3. ConstraintViolation methods Now it is time to have a closer look at what a ConstraintViolation. Using the different methods of ConstraintViolation a lot of useful information about the cause of the validation failure can be determined. Table 2.1, “The various ConstraintViolation methods” gives an overview of these methods: Table 2.1. The various ConstraintViolation methods Method Usage Example (referring to Example 2.9, “Usage of Validator.validate()”) getMessage() The interpolated error message. may not be null getMessageTemplate() The non-interpolated error message. {javax.validation.constraints.NotNull.message} getRootBean() The root bean being validated. car getRootBeanClass() The class of the root bean being validated. Car.class getLeafBean() If a bean constraint, the bean instance the constraint is applied on. If a property constraint, the bean instance hosting the property the constraint is applied on. car getPropertyPath() The property path to the value from root bean. getInvalidValue() The value failing to pass the constraint. passengers getConstraintDescriptor() Constraint metadata reported to fail.