0

I am describing request data parameter using Java, SpringBoot and Swagger. Normally I would define which parameter is required using @ApiModelProperty or @NotBlank annotation. But I have this case: I have two parameters. Both are optional. But, when send this request data, one of two must be filled, otherwise validation error is expected.

public class ABC{
   @ApiModelProperty(notes="FieldA", required= false)
   @NotBlank
   String fieldA;

   String fieldB;
}

my question are

  • How to validate this condition before sending the request to API server?
  • Is there any available annotation to handle this input validation?
  • Or there is no other way than handling it in the service server using if-else condition and check whether fieldA is null, then fieldB cannot be null, etc?
chronos14
  • 321
  • 1
  • 5
  • 20
  • 1
    Something like this? https://stackoverflow.com/questions/2781771/how-can-i-validate-two-or-more-fields-in-combination – DanielBarbarian Sep 16 '19 at 10:47
  • 1
    I think `3rd` approach is much appropriate. Using `3rd` approach you have more control over it. Like `if(fieldA==null && fieldB==null){//throw validation error}` – Sudhir Ojha Sep 16 '19 at 10:48

0 Answers0