title: Handling map-like request parameters in Spring MVC
body: <p>Say I have a form for a list of questions where I need a 0/1 answer. I could easily model a static list with radios, something like</p>
  
  <pre><code>&lt;input type="radio" name="question1" value="0"&gt;
  &lt;input type="radio" name="question1" value="1"&gt;
  &lt;br&gt;
  &lt;input type="radio" name="question2" value="0"&gt;
  &lt;input type="radio" name="question2" value="1"&gt;
  
  @RequestMapping("/answer")
  public String answer(Integer question1, Integer question2) {
  </code></pre>
  
  <p>But I have a dynamic list of questions instead, where each question has a numeric ID. I therefore tried to model it like the following (the HTML is dynamically created with an iteration on the question list):</p>
  
  <pre><code>&lt;input type="radio" name="question[42]" value="0"&gt;
  &lt;input type="radio" name="question[42]" value="1"&gt;
  &lt;br&gt;
  &lt;input type="radio" name="question[51]" value="0"&gt;
  &lt;input type="radio" name="question[51]" value="1"&gt;
  </code></pre>
  
  <p>where 42 and 51 are the question id.
  I was expecting to capture all values in a Map parameter of my Spring controller, like so:</p>
  
  <pre><code>@RequestMapping("/answer")
  public String answer(@RequestAttribute("question") HashMap&lt;Integer, Integer&gt; question) {
  </code></pre>
  
  <p>It didn't work (the method isn't called).
  I also tried with string ids:</p>
  
  <pre><code>&lt;input type="radio" name="question['42']" value="0"&gt;
  
  @RequestMapping("/answer")
  public String answer(@RequestAttribute("question") HashMap&lt;String, Integer&gt; question) {
  </code></pre>
  
  <p>Same as before.
  It only works if I use a map of string/string, but in this case I get all request parameters in the map, which I will then need to parse:</p>
  
  <pre><code>@RequestMapping("/answer")
  public String answer(@RequestAttribute("question") HashMap&lt;String, String&gt; question) {
  
  --&gt; question.keys: "question[42]", "question[51]"
  </code></pre>
  
  <p>So what is the proper way of handling dynamic radios, or more generally map-like request parameters?</p>