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
@NoArgsConstructor
public 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?