DigitsValidator and EANValidator are not serializable.

Description

Hi all,

If you try to serialize a DigitsValidator and EANValidator validator class instance, then you get a nice:

java.io.NotSerializableException: org.hibernate.validator.DigitsValidator
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)

An easy way to reproduce it is to run the following unit test:

public class ValidatorTest {
@Test(dataProvider = "getValidators")
public void testValidatorSerialization(Validator<?> validator) throws IOException {
OutputStream os = new ByteArrayOutputStream();
new ObjectOutputStream(os).writeObject(validator);
}

@DataProvider(name = "getValidators")
public Object[][] getValidators() {
return new Object[][] {
{new AssertFalseValidator()},
{new AssertTrueValidator()},
{new CreditCardNumberValidator()},
{new DigitsValidator()},
{new EANValidator()},
{new EmailValidator()},
{new FutureValidator()},
{new LengthValidator()},
{new MaxValidator()},
{new MinValidator()},
{new NotEmptyValidator()},
{new NotNullValidator()},
{new PastValidator()},
{new PatternValidator()},
{new RangeValidator()},
{new SizeValidator()},
};
}
}

To fix it you should simply make the two classes implementing Serializable.

Environment

None

Assignee

Unassigned

Reporter

benoit heinrich

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Major
Configure