I have a @PostMapping
that allows the user to send a plain json
map, like:
{
"firstname": "john",
"lastname": "doh"
}
Servlet:
@RestController
public class PersonController {
@PostMapping("/generic")
public void post(Map<String, String> params) {
}
}
This works fine. But now I want to accept also a list of objects on the same endpoint. But I cannot just add another method that takes a different parameter. Because spring the complains about ambiguous mapping:
@PostMapping("/generic")
public void post2(List<Map<String, String>> params) {
}
Question: how can I accept json
data that can be both a Map
and a List
? I could lateron continue in the business code conditionally if the input is either map/list. But how can I accept them at all in a spring controller side by side?