79231364

Date: 2024-11-27 17:51:24
Score: 1
Natty:
Report link

Why don't you validate the params inside? like:

@ResponseStatus(HttpStatus.OK)
@GetMapping()
public void foo(@RequestParam(value = "someValue1", required = false) String someValue1, 
                @RequestParam(value = "someValue2", required = false) final String someValue2) {
    // Do validation here
    if (someValue1 == null && someValue2 == null) {
        throw new BadRequestException("someValue1 or someValue2 has to be present");
    }
    
    if (someValue1 != null) {
        // use someValue1
    }
    
    if (someValue2 != null) {
        // use someValue2
    }
    
}

Spring doesn't have an build in feature for that case, at least i don't know it

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Why don't you
  • Low reputation (1):
Posted by: Mat Kollin