Spring RestTemplateで配列パラメータを送信するにはどうすればよいですか?
これはサーバー側の実装です:
@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)
{
...
}
これは私が試したことです:
Map<String, Object> map = new HashMap<String, Object>();
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}&positiveDocId[]={positiveDocId[]}&negativeDocId[]={negativeDocId[]}", TrainResponse.class, map);
以下は、明らかに間違っている実際のリクエスト URL です。
http://localhost:8080/admin/train?category=spam&positiveDocId%5B%5D=%5BLjava.lang.String;@4df2868&negativeDocId%5B%5D=%5BLjava.lang.String;@56d5c657`
周りを検索しようとしましたが、解決策を見つけることができませんでした。任意のポインタをいただければ幸いです。