|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Data REST 5.1.2! |
Validation
Assigning Validators
To register a Validator instance, implement RepositoryRestConfigurer, override configureValidatingRepositoryEventListener, and call addValidator on the ValidatingRepositoryEventListener, passing the event on which you want this validator to be triggered and an instance of the validator. The following example shows how to do so:
@Override
public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener v) {
v.addValidator("beforeSave", new BeforeSaveValidator());
}
Validation Events
A validator runs when its event is published and validates the object the event carries. For link events, that is the parent entity. See Event Lifecycle and Object State for when each event fires and which object it carries.
The following table maps event names to events:
| Event Name | Event |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BeforeLinkDeleteEvent and AfterLinkDeleteEvent do not trigger validation.