(Hash)-Map as RequestParam in a spring-boot application

39 Views Asked by At
  • I want to specify filters for a CRUD GET REST controller for a list of items.

  • The items I do return have a name name: String, a boolean property isFoo: boolean and labels: Map<String, String>.

  • My list controller uses q for the name-filter and isFoo for the boolean property.

  • Now I want to filter on labels as well.

  • Additionally I use org.springframework.data.domain.Page to return sub-sets.

  • I declared it naively like this and tested by adding labels=%7Ba%3Db%2C+c%3Dd%7D

@GetMapping("")
MyReturnType list(
  @RequestParam(defaultValue = 0) final int page,
  @RequestParam(defaultValue = 10) final int size,
  @RequestParam(defaultValue = true) final boolean isFoo,
  @RequestParam(required = false) final String q,
  @RequestParam(required = false, name = "labels") final Map<String, String> labels) {
...
}
  • However I get a HTTP 500
  • How may I specify this?
0

There are 0 best solutions below