spring-projects / spring-projects/spring-data-rest
Document how to enable validating entities with JSR-303 bean validation annotations [DATAREST-372]
Open
@odrotbohm is already working on this.
Since Dec 31, 2020.
type: documentation
type: enhancement
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Marcel Overdijk opened DATAREST-372 and commented
The Spring Data REST homepage states:
- Validate entities with JSR-303 or Spring Validator beans
However in the documentation I cannot find back how this should be enabled.
By default entities with JSR-303 annotation are not validated.
What I did to make it working is:
@Configuration
protected static class CustomRepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration {
@Autowired
private Validator validator;
@Override
protected void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
validatingListener.addValidator("beforeCreate", validator);
validatingListener.addValidator("beforeSave", validator);
}
}
I don't know if this the best way to enable JSR-303 bean validation but either way I think it's good to add to the documentation how to enable it
Affects: 2.1.2 (Dijkstra SR2)
6 votes, 8 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.