Annotation Interface CustomValidateHandler
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(
@CustomValidateHandler(handler = PortValidator.class)
int port
) {}
- 関連項目:
-
FieldValidator
-
必須要素の概要
必須要素
-
要素の詳細
-
handler
Class<? extends net.ririfa.yacla.loader.FieldValidator> handlerSpecifies the validator class that will be invoked on this field during validation.- 戻り値:
- the class implementing
FieldValidator
-