/** * Validates the given value as if it were the value of the bean property * configured for this validator. Returns {@code Result.ok} if there are no * JSR-303 constraint violations, a {@code Result.error} of chained * constraint violation messages otherwise. * <p> * Null values are accepted unless the property has an {@code @NotNull} * annotation or equivalent. * * @param value * the input value to validate * @param context * the value context for validation * @return the validation result */ @Override public ValidationResult apply(final Object value, ValueContext context) { Set<? extends ConstraintViolation<?>> violations = getJavaxBeanValidator() .validateValue(beanType, propertyName, value); Locale locale = context.getLocale().orElse(Locale.getDefault()); Optional<ValidationResult> result = violations.stream() .map(violation -> ValidationResult .error(getMessage(violation, locale))) .findFirst(); return result.orElse(ValidationResult.ok()); }
private void configureRequired(BindingBuilder<BEAN, ?> binding, PropertyDefinition<BEAN, ?> definition, BeanValidator validator) { assert requiredConfigurator != null; Class<?> propertyHolderType = definition.getPropertyHolderType(); BeanDescriptor descriptor = validator.getJavaxBeanValidator() .getConstraintsForClass(propertyHolderType); PropertyDescriptor propertyDescriptor = descriptor .getConstraintsForProperty(definition.getTopLevelName()); if (propertyDescriptor == null) { return; } if (propertyDescriptor.getConstraintDescriptors().stream() .map(ConstraintDescriptor::getAnnotation) .anyMatch(requiredConfigurator)) { binding.getField().setRequiredIndicatorVisible(true); } }