I have the following PUT method in my Spring Controller class. There is a parameter annotated with @PathVariable. There is another parameter annotated with @RequestBody @Valid. The problem is RequestBody is getting validated first and the method returns in case of exception. But I want @Pathvariable to be validated first and return in case of exception.
@RestController
@Validated
@RequestMapping(value = "/v1/order", produces = MediaType.APPLICATION_JSON_VALUE)
public class OrderMappingController {
@PutMapping(value = "/{id}/order-mapping", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> UpdateOrderMapping(@PathVariable(value = "id") @NotBlank(message = "InvalidID")
@ValidOrderId String id,
@RequestBody @Valid OrderMappingRequest request) {
//...
}
}
Thanks in Advance!