I have a REST api in Spring Boot:
@GetMapping("/test")
public MyClass getData() {
return something;
}
This endpoint can be requested with up to 10 RequestParams. I know of course all of the 10 possible RequestParams, however client can chose to request with anywhere between 0 to all 10 of the RequestParams.
Now I need a way to handle this without plugging all 10 RequestParams in as parameters in the getData() method. Is it not possible to register all possible RequestParams in a class, and the use that class as parameter ing the getData()?
Something like this:
public class ParamClass {
private @RequestParam("ParamOne") String ParamOne;
private @RequestParam("ParamTwo") Set<String> ParamTwo;
private @RequestParam("ParamThree") Integer ParamThree;
}
And then
@GetMapping("/test")
public MyClass getData(@RequestParam ParamClass params) {
return something;
}
Please note: The parameters can be different types (String, int, Set, etc.) therefore the following solution comes very close but does not solve it because the map requires a consistent value type: how to capture multiple parameters using @RequestParam using spring mvc?