I have some questions regarding RequestParam conversions.
For the most part I have simple conversions working however when it comes to more complex objects things arent working the way they would seem.
For example. How are lists/arrays handled when the type is any other type of object other than string?
http://localhost:8080/spring/foo?bar=1,2,3Code:@ResponseBody RequestMapping(value = "/foo") public String foo(@RequestParam(value ="bar", required=true) List<Integer> fooIds) { ... }
or
http://localhost:8080/spring/foo?bar=1&bar=2&bar=3
Whenever I try to access the list of fooIds as Integers I get a Cannot cast from String to Integer exceptions. I would have thought this simple conversion would be accomplished. If i change the type to List<String> everything is works as expected.
Now for more complex objects:
Code:public Foo { public Foo(List<String> bars) { ..... } }Now in this example I would think that the Foo class would receive a List<String> as a constructor argument but it doesn't'. If i change or add a constructor that expects a single string then it will work. How would I handle this situation?Code:@ResponseBody RequestMapping(value = "/foo") public String foo(@RequestParam(value ="bar", required=true) Foo myFoo) { ... }
Obviously I am missing something so can someone please clarify these issues for me?
Thanks for any help!


Reply With Quote
