2

I am implementing a web service using spring boot 1.3.6. In my controller, I have a method like:

@RequestMapping(value = "/employees/{id}", method = RequestMethod.PUT)    
createEmployee(@PathVariable String id, 
               @QueryParam(required = false, value = "department") Set<String> departments)

I want to collect the request parameters in a class like:

class EmployeeParams {
    public String id;
    public Set<String> departments;
}

I tried using:

@RequestMapping(value = "/employees/{id}", method = RequestMethod.PUT)    
createEmployee(EmployeeParams param) { ... } 

But it does not work. I get the id in above class but not departments. What is the proper way of collecting the request parameters in Spring requests?

Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151
Aarkan
  • 3,811
  • 6
  • 40
  • 54

1 Answers1

1

You should add a custom converter that implements Spring org.springframework.core.convert.converter.Converter<String, EmployeeParams> and register it with Spring.

See Spring documentation.
This stack overflow issue also discusses some details on adding a custom converter or formatter.

Community
  • 1
  • 1
Alexander
  • 2,761
  • 1
  • 28
  • 33