public interface Validatable
Chronicle libraries call ValidatableUtil.validate(Object) before
serialising method-writer arguments and it is common to invoke it from
toString() whilst debugging. Validation can be temporarily disabled
by wrapping the call in ValidatableUtil.startValidateDisabled() and
ValidatableUtil.endValidateDisabled().
Example usage:
public class MyData implements Validatable {
private String name;
private Integer age;
// getters and setters
@Override
public void validate() throws InvalidMarshallableException {
if (name == null || name.isEmpty())
throw new InvalidMarshallableException("Name cannot be null or empty");
if (age == null || age < 0)
throw new InvalidMarshallableException("Age cannot be null or negative");
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
validate()
Validates the state of the object.
|
void validate()
throws InvalidMarshallableException
This method should be called prior to writing the object via a method writer.
Implementations should check the state of the object and throw an
InvalidMarshallableException if the object is in an invalid state.
For example, this could involve checking for null values in required fields, validating that numerical values are within acceptable ranges, etc.
InvalidMarshallableException - if the object is in an invalid state,
such as having null values in required fields or values
out of acceptable range.RuntimeException - if an unexpected error occurs during validation.Copyright © 2026 Chronicle Software Ltd. All rights reserved.