1

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

Nathanael
  • 195
  • 2
  • 2
  • 7
  • "doesn't work" why not? what happens? what would be instead of `// code goes here`? – underscore_d Oct 13 '20 at 13:07
  • `//code goes here` is the typical service call and the call to the repository/DB. What I meant by doesn't work is that the validation doesn't check if the inputs are valid or not. – Nathanael Oct 13 '20 at 13:54

0 Answers0