title: How to send array with Spring RestTemplate?
body: <p>How do I send array parameter with Spring RestTemplate?</p>
  
  <p>This is the server side implementation:</p>
  
  <pre><code>@RequestMapping(value = "/train", method = RequestMethod.GET)
  @ResponseBody
  public TrainResponse train(Locale locale, Model model, HttpServletRequest request, 
      @RequestParam String category,
      @RequestParam(required = false, value = "positiveDocId[]") String[] positiveDocId,
      @RequestParam(required = false, value = "negativeDocId[]") String[] negativeDocId) 
  {
      ...
  }
  </code></pre>
  
  <p>This is what I've tried:</p>
  
  <pre><code>Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
  map.put("category", parameters.getName());
  map.put("positiveDocId[]", positiveDocs); // positiveDocs is String array
  map.put("negativeDocId[]", negativeDocs); // negativeDocs is String array
  TrainResponse response = restTemplate.getForObject("http://localhost:8080/admin/train?category={category}&amp;positiveDocId[]={positiveDocId[]}&amp;negativeDocId[]={negativeDocId[]}", TrainResponse.class, map);
  </code></pre>
  
  <p>The following is the actual request URL which is obviously incorrect:</p>
  
  <pre><code>http://localhost:8080/admin/train?category=spam&amp;positiveDocId%5B%5D=%5BLjava.lang.String;@4df2868&amp;negativeDocId%5B%5D=%5BLjava.lang.String;@56d5c657`
  </code></pre>
  
  <p>Have been trying to search around but couldn't find a solution. Any pointers would be appreciated.</p>