I am fairly familiar with the JSR-303's @Valid
annotation and have used it a couple of times in my @Controller
classes. For example:
@PostMapping("/users")
ResponseEntity<String> addUser(@Valid @RequestBody User user) {
// persisting the user
return ResponseEntity.ok("User is valid");
}
Where User
object is a typical class with annotations like @NotBlank
or @NotNull
on the fields.
However, I am trying to build a REST API based on JSON API using the crnk library and am trying to do the same validation, example:
@Override
public Subscription save(@Valid Subscription subscription) {
// code goes here
}
Unfortunately the validation doesn't work and I have tried both @Valid
and @Validation
.
Can anyone kindly show what is wrong with this code?
Thanks