0

I need to add a '-' in the path parameter name, because of the backward compatibility of our project.

@GetMapping("employees")

public ResponseEntity<Object> getEmployeesBySelection(@PathParam("page-size") Optional < Integer> page_size)
{

ResponseEntity.ok(page_size.orElse(0));

}

If it is set up like this it returns an empty object. (the reason for use of Optional)

I found a similar question on this site but it looked like they were all just trying to solve it by transforming the pathParam into camel-case via a custom request wrapper.

Is there some kind of general solution to enable spring to recognize pathParams with '-' as written above?

Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36
Rejja Kubzek
  • 81
  • 1
  • 6
  • https://stackoverflow.com/questions/33924200/mapping-url-parameters-with-dashes-to-object-in-spring-web-mvc – Joop Eggen Aug 31 '22 at 09:34
  • 3
    Are you sure `@PathParam` is the correct annotation ? Spring uses `@PathVariable` (see https://stackoverflow.com/q/41657428/1076463) – Robin Aug 31 '22 at 09:35

0 Answers0