Custom Validate Handler
Attaches a custom FieldValidator to the annotated field, allowing advanced validation logic beyond built-in annotations like @Required or @Range.
This is useful when the field needs domain-specific checks, cross-field conditions, or dynamic rules that cannot be expressed declaratively.
The validator is instantiated via no-arg constructor and executed during loader.validate().
Example:
public class PortValidator implements FieldValidator {
public void validate(Object value, Object configInstance) {
int port = (int) value;
if (port < 1024 || port > 65535) {
throw new IllegalArgumentException("Port must be between 1024 and 65535");
}
}
}
public record ServerConfig(
= PortValidator.class)
int port
) {}
Content copied to clipboard