SpringBoot List Validation

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?
1 Reply
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @YoungMoneyMitch! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.
Want results from more Discord servers?
Add your server