I am using springBoot 2 and I am trying to validate the objects in a List via:
@RequestMapping(value = "/bets",
produces = {"application/json"},
consumes = {"application/json"},
method = RequestMethod.POST
)
void postBets(@RequestBody List<@Valid Bet> bets);
and Bet class has @NotNull annotations on certain attributes.
import javax.validation.constraints.NotNull;
public class Bet extends BetMessage {
@NotNull
private String categoryName;
@NotNull
private String marketName = null;
@NotNull
private OffsetDateTime startTime = null;
@NotNull
private String betName = null;
I have also added the spring-boot-starter-validation artifact to my build file but still no validation is happening.
As a workaround I have implemented the popular answer in the question below (ValidList class) and validation is working as expected; however I think that I am missing something obvious and the solution is now part of the validation library.