I have a field in a bean annotated as such:
Code:
@UnwrapValidatedValue
@Valid
private Optional<List<MyCustomType>> stuff = Optional.absent();
I would hope that the @Valid would cause each of the instances of MyCustomType in the List to be validated, but as of yet I have not been able to get that to work. The unwrapping works correctly so that the List itself is validated if I apply @NotNull or other such annotations, but the @Valid annotation does not cause the elements of the list to be validated.
My value unwrapper looks like:
Code:
import org.hibernate.validator.spi.valuehandling.ValidatedValueUnwrapper;
import com.fasterxml.classmate.TypeResolver;
import com.google.common.base.Optional;
public class OptionalValueUnwrapper extends ValidatedValueUnwrapper<Optional<?>>
{
private final TypeResolver typeResolver = new TypeResolver();
@Override
public Object handleValidatedValue(Optional<?> value)
{
if (!value.isPresent()) {
return null;
}
return value.get();
}
@Override
public Type getValidatedValueType(Type valueType)
{
ResolvedType resolvedType = typeResolver.resolve(valueType);
return resolvedType.typeParametersFor(Optional.class).get(0).getErasedType();
}
}
I am using hibernate-validator 5.1.1.Final
Any suggestions?
Thank you!