I want to validate two fields of a Request Class in manner that Either one field is valid OR another field is valid.
Eg: Request Bean
public class CarRequest {
@NotEmpty
private String customerName;
@NotEmpty
private String customerId;
Controller Method
public @ResponseBody CarResponse addCar(
@ModelAttribute @Valid CarRequest request, BindingResult results)
throws RuntimeException, ValidationException {
if (results.hasErrors()) {
LOG.error("error occured while adding the car");
throw new ValidationException(
"Error Occoured while validiating car request");
}
}
Here I want to check that either customerName should be NotEmpty OR customerId should be NotEmpty. then my validation should pass. How can I implement it . Please suggest!!