0

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.

Validation of a list of objects in Spring

JoeyHolloway
  • 458
  • 7
  • 19

1 Answers1

-1

You may want to write a wrapper which contains your list of Bet because then your wrapper will conform to JavaBean specs and the validations can be applied.

Below Answer might help in this case.

@Valid on list of beans in REST service

Sharman25
  • 69
  • 4