Say I have a GET endpoint in Spring Boot controller, which accepts an object as @RequestParam
@GetMapping(value = "/foos")
public List<Foo> getFoos(@RequestParam FilterParams filterParams) {
return fooDao.getFoos(filterParams);
}
where FilterParams is a class which contains a List attribute (or whatever other list of Objects)
public class FilterParams {
public List<Bar> bars;
}
and Bar is an enum (for this example)
public enum Bar {
Baz, Zap
}
If we post a GET request on this endpoint with a list of filterParameter attributes seperated by "," i.e.
curl -X GET localhost:8080/foos?bars=BAZ,ZAP
, Spring fails to parse it as a List and tries to deserialize one single value BAZ,ZAP
into an enum. If it weren't an enum, it would also behave the same, i.e. deserialize parameter id=1,2 into a single element of a list of Strings. Is it possible to override this behaviour? And if so, how would one achieve this?
I do know that i could achieve this by declaring multiple parameters as /foos?bars=BAZ&bars=ZAP
but it is not convenient for me