本文整理汇总了Java中javax.validation.ConstraintViolation.getInvalidValue方法的典型用法代码示例。如果您正苦于以下问题:Java ConstraintViolation.getInvalidValue方法的具体用法?Java ConstraintViolation.getInvalidValue怎么用?Java ConstraintViolation.getInvalidValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.ConstraintViolation
的用法示例。
在下文中一共展示了ConstraintViolation.getInvalidValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: errorMessage
import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
private String errorMessage(ConstraintViolation<?> error) {
Set<Class<? extends Payload>> payload = error.getConstraintDescriptor().getPayload();
if (payload.contains(NoLogging.class)) {
return error.getPropertyPath().toString() + ", " + error.getMessage();
} else {
return error.getPropertyPath().toString() + ", " + error.getMessage() + ", was: " + error.getInvalidValue();
}
}
示例2: contOnValidationError
import javax.validation.ConstraintViolation; //导入方法依赖的package包/类
/**
* Accepts the result from one of the many validation methods available and
* returns a List of ValidationErrors. If the size of the List is 0, no errors
* were encounter during validation.
*
* Usage:
* <pre>
* Validator validator = getValidator();
* List<ValidationError> errors = contOnValidationError(
* validator.validateProperty(myObject, "uuid"),
* validator.validateProperty(myObject, "name")
* );
* // If validation fails, this line will be reached.
* </pre>
*
* @param violationsArray a Set of one or more ConstraintViolations
* @return a List of zero or more ValidationErrors
* @since 1.0.0
*/
@SafeVarargs
protected final List<ValidationError> contOnValidationError(final Set<ConstraintViolation<Object>>... violationsArray) {
final List<ValidationError> errors = new ArrayList<>();
for (Set<ConstraintViolation<Object>> violations : violationsArray) {
for (ConstraintViolation violation : violations) {
if (violation.getPropertyPath().iterator().next().getName() != null) {
final String path = violation.getPropertyPath() != null ? violation.getPropertyPath().toString() : null;
final String message = violation.getMessage() != null ? StringUtils.removeStart(violation.getMessage(), path + ".") : null;
final String messageTemplate = violation.getMessageTemplate();
final String invalidValue = violation.getInvalidValue() != null ? violation.getInvalidValue().toString() : null;
final ValidationError error = new ValidationError(message, messageTemplate, path, invalidValue);
errors.add(error);
}
}
}
return errors;
}