Quantcast
Viewing all articles
Browse latest Browse all 3690

Spring Boot request body validation

I am working on Spring REST API and have following controller:

@RestController@RequestMapping(        value = "/api/Test",        produces = "application/json")public class MyController {    @RequestMapping(method = RequestMethod.POST)    public Response serviceRequest(@Valid @RequestBody ServiceRequest myServiceRequest)  {                 ....        }}

ServiceRequest has following structure:

@Getter@Setter@AllArgsConstructor@NoArgsConstructorpublic class ServiceRequest {    @NotBlank    private LocalDate fromDate;    @NotBlank    private LocalDate toDate;}

My task is to introduce validation based on combination of fromDate and toDate field's values: if time period between them is longer that 1 week then validation should fail.

What is the best way to archive this please?


Viewing all articles
Browse latest Browse all 3690

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>