SpringValidatorAdapter's ObjectError subclasses are serializable

Closes gh-23181
This commit is contained in:
Juergen Hoeller
2019-07-05 17:07:01 +02:00
parent 2aec175ccc
commit aeef95938e
4 changed files with 113 additions and 49 deletions

View File

@@ -48,6 +48,7 @@ import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.context.support.StaticMessageSource;
import org.springframework.util.ObjectUtils;
import org.springframework.util.SerializationTestUtils;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.FieldError;
@@ -86,7 +87,7 @@ public class SpringValidatorAdapterTests {
}
@Test // SPR-13406
public void testNoStringArgumentValue() {
public void testNoStringArgumentValue() throws Exception {
TestBean testBean = new TestBean();
testBean.setPassword("pass");
testBean.setConfirmPassword("pass");
@@ -101,10 +102,11 @@ public class SpringValidatorAdapterTests {
assertThat(messageSource.getMessage(error, Locale.ENGLISH), is("Size of Password must be between 8 and 128"));
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("password"));
assertThat(SerializationTestUtils.serializeAndDeserialize(error.toString()), is(error.toString()));
}
@Test // SPR-13406
public void testApplyMessageSourceResolvableToStringArgumentValueWithResolvedLogicalFieldName() {
public void testApplyMessageSourceResolvableToStringArgumentValueWithResolvedLogicalFieldName() throws Exception {
TestBean testBean = new TestBean();
testBean.setPassword("password");
testBean.setConfirmPassword("PASSWORD");
@@ -119,6 +121,7 @@ public class SpringValidatorAdapterTests {
assertThat(messageSource.getMessage(error, Locale.ENGLISH), is("Password must be same value as Password(Confirm)"));
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("password"));
assertThat(SerializationTestUtils.serializeAndDeserialize(error.toString()), is(error.toString()));
}
@Test // SPR-13406
@@ -473,10 +476,10 @@ public class SpringValidatorAdapterTests {
.addPropertyNode(f.getName())
.addConstraintViolation();
}
} catch (IllegalAccessException ex) {
}
catch (IllegalAccessException ex) {
throw new IllegalStateException(ex);
}
});
return fieldsErros.isEmpty();
}