@SuppressWarnings({ "rawtypes", "unchecked" }) private Object getBeanPropertyValue(ValidationContext<?> validationContext, Object object, Cascadable cascadable) { Object value = cascadable.getValue( object ); // Value can be wrapped (e.g. Optional<Address>). Try to unwrap it UnwrapMode unwrapMode = cascadable.unwrapMode(); if ( UnwrapMode.UNWRAP.equals( unwrapMode ) || UnwrapMode.AUTOMATIC.equals( unwrapMode ) ) { ValidatedValueUnwrapper valueHandler = validationContext.getValidatedValueUnwrapper( cascadable.getCascadableType() ); if ( valueHandler != null ) { value = valueHandler.handleValidatedValue( value ); } } return value; }
private <T, V> ConstraintValidator<A, V> getInitializedConstraintValidator(ValidationContext<T> validationContext, ValueContext<?, V> valueContext) { Type validatedValueType = valueContext.getDeclaredTypeOfValidatedElement(); @SuppressWarnings("unchecked") ValidatedValueUnwrapper<V> validatedValueUnwrapper = (ValidatedValueUnwrapper<V>) validationContext .getValidatedValueUnwrapper( validatedValueType ); // AUTOMATIC mode, need to determine which types of constraint validators are available if ( valueContext.getUnwrapMode().equals( UnwrapMode.AUTOMATIC ) ) { return getConstraintValidatorInstanceForAutomaticUnwrapping( validationContext, valueContext ); } // TYPE_USE requires implicitly unwrapping else if ( valueContext.getUnwrapMode().equals( UnwrapMode.UNWRAP ) || TYPE_USE.equals( valueContext.getElementType().name() ) ) { return getInitializedValidatorInstanceForWrappedInstance( validationContext, valueContext, validatedValueType, validatedValueUnwrapper ); } // UnwrapMode.SKIP_UNWRAP else { return getConstraintValidatorNoUnwrapping( validationContext, valueContext ); } }
@SuppressWarnings("unchecked") ValidatedValueUnwrapper<V> validatedValueUnwrapper = (ValidatedValueUnwrapper<V>) validationContext .getValidatedValueUnwrapper( validatedValueType );