本文整理匯總了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;
}