Howdy everybody!
How are you supposed to validate objects in a list being passed to a controller in SpringBoot? I am trying to use the @Valid @NotBlank etc validation annotations but they seem to only work on individual beans. I have seen people suggesting to wrap a list in a custom class but then wouldn't that just be validating the wrapper class and not the internal bean?
Here is an example:
@PostMapping("subtotalBeforeDiscount")
public ResponseEntity<BigDecimal> getSubtotalBeforeDiscount(@RequestBody List<Item> items) {
log.info("/subtotalBeforeDiscount, executing SubtotalBeforeDiscountService");
return new ResponseEntity<>(subtotalBeforeDiscountService.calculateSubtotalBeforeDiscountService(items), HttpStatus.OK);
}
I want to validate Item in the params, and I have all of the data validation annotations in the Item class.
Am I approaching validation wrong?