Fixed regression in SpringValidatorAdapter's retrieval of invalid values
Issue: SPR-10243
This commit is contained in:
parent
19eecb151b
commit
cef97819c5
|
@ -130,7 +130,8 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
|
|||
}
|
||||
else {
|
||||
Object invalidValue = violation.getInvalidValue();
|
||||
if (field.contains(".") && !field.contains("[]")) {
|
||||
if (!"".equals(field) && (invalidValue == violation.getLeafBean() ||
|
||||
(field.contains(".") && !field.contains("[]")))) {
|
||||
// Possibly a bean constraint with property path: retrieve the actual property value.
|
||||
// However, explicitly avoid this for "address[]" style paths that we can't handle.
|
||||
invalidValue = bindingResult.getRawFieldValue(field);
|
||||
|
|
|
@ -35,7 +35,6 @@ import javax.validation.Valid;
|
|||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.hibernate.validator.HibernateValidator;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
|
@ -43,7 +42,7 @@ import org.springframework.validation.Errors;
|
|||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.ObjectError;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
|
@ -105,7 +104,6 @@ public class ValidatorFactoryTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testSpringValidationFieldType() throws Exception {
|
||||
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
|
||||
validator.afterPropertiesSet();
|
||||
|
@ -115,8 +113,7 @@ public class ValidatorFactoryTests {
|
|||
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(person, "person");
|
||||
validator.validate(person, errors);
|
||||
assertEquals(1, errors.getErrorCount());
|
||||
assertThat("Field/Value type missmatch",
|
||||
errors.getFieldError("address").getRejectedValue(),
|
||||
assertThat("Field/Value type mismatch", errors.getFieldError("address").getRejectedValue(),
|
||||
instanceOf(ValidAddress.class));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue