Nithya
Nithya

Reputation: 1

This annotation is not allowed at this location (@Valid)

I am trying to validate the list which is passed as a parameter to a controller in spring-boot application. I referred Baeldung doc to perform the same, below is the code snippet which i tried to implement

@PostMapping
public void addAll(@RequestBody @NotEmpty(message = "Input movie list cannot be empty.") List<@Valid Movie> movies) {
    movieService.addAll(movies);
}

but it throws an error saying "@Valid annotation is not allowed in this location" (this is compile time error, i haven't executed the code hence there is no stacktrace)

Suggest a fix for the same

I did the same thing as shown in the image

Upvotes: -1

Views: 141

Answers (1)

Dirk Hoffmann
Dirk Hoffmann

Reputation: 1563

make sure the @Valid annotaion is in front of the List and not the generic list type. Also make sure your Movie class implements @Valid validations.

Upvotes: 0

Related Questions