Interface Validator
- All Known Implementing Classes:
Jsr380Validator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Strategy interface for validating message payloads and other objects prior to handler invocation.
Implementations of this interface are typically invoked by the ValidatingInterceptor, which is automatically
registered by the Fluxzero client. Validation occurs before the message is passed to the handler method.
A Validator is responsible for detecting constraint violations and producing a ValidationException if
applicable. It supports validation groups to selectively apply rules.
Usage
The validator may be used programmatically:validator.assertValid(new CreateUserCommand(...));
But more commonly, it is used implicitly:
- When the
ValidatingInterceptoris registered with theHandlerFactory - Or when using dependency injection or framework-level validation support
Custom Implementations
Custom validators can be created to support use cases like:- JSR 380 / Bean Validation annotations (e.g.,
@NotNull,@Size) - Domain-specific validation rules
- Structural validation on incoming
web requests
This interface is designed to be functional and composable, enabling fluent use within client applications.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> TassertValid(T object, Class<?>... groups) Validates the given object and throws aValidationExceptionif it is invalid.checkValidity(T object, Class<?>... groups) Validates the given object and returns an optionalValidationExceptionif the object is invalid.default booleanChecks whether the given object is valid according to the defined validation rules.
-
Method Details
-
checkValidity
Validates the given object and returns an optionalValidationExceptionif the object is invalid.- Type Parameters:
T- the type of object being validated- Parameters:
object- the object to validategroups- optional validation groups to apply- Returns:
- an
Optionalcontaining the validation error if validation failed, or empty if valid
-
assertValid
Validates the given object and throws aValidationExceptionif it is invalid.- Type Parameters:
T- the type of object being validated- Parameters:
object- the object to validategroups- optional validation groups to apply- Returns:
- the original object if valid
- Throws:
ValidationException- if the object is invalid
-
isValid
-