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(
    = PortValidator.class)
    int port
) {}

See also

Functions

Link copied to clipboard
abstract fun annotationType(): Class<out Annotation>
Link copied to clipboard
abstract fun equals(p: Any): Boolean
Link copied to clipboard
abstract fun handler(): Class<out FieldValidator>
Specifies the validator class that will be invoked on this field during validation.
Link copied to clipboard
abstract fun hashCode(): Int
Link copied to clipboard
abstract fun toString(): String