We're building a simple rest API using Spring Web MVC. One of our handlers takes as a request parameter an int called ID.
@RequestMapping(value="/requestEntity",
method=RequestMethod.GET)
public ModelMap getEntity(
@PathVariable(value="id")final Integer id,
HttpServletResponse response) throws IOException {
I know that the request object has the request parameter values as strings (name1=value1&name2=22) and that the handler will magically receive an int when it has ID as its parameter.
"/requestEntity", id="5" -> getEntity(5);
Unfortunately, if we send the value "1 2 3" as input, we get as an argument the number 123. If we send "5;123" we get 5 as an argument.
"/requestEntity", id="1 2 3" -> getEntity(123); // WRONG -- we want to throw an error
"/requestEntity", id="5;123" -> getEntity(5); // ALSO WRONG
As far as I can tell, Spring is doing some conversion to turn the string parameter values into the int argument that the handler needs. How can we implement our own argument converter?