I'm working on a Spring Boot application. I have the following REST endpoint(s):
@GetMapping(value = { "/person/{name}", "/person/{age}" })
public PersonData getPersonData(@PathVariable(required = false) String name,
@PathVariable(required = false) Integer age) {
}
This endpoint can be called with either a name variable or an age variable, however it looks like it can't differentiate between them. If I was to call '.../person/20', it would not call "/person/{age}", but it always calls "/person/{name}".
I know I could make something like:
@GetMapping(value = { "/person/name/{name}", "/person/age/{age}" })
However are there any other way to solve it without adding anything to the path?