I am trying to post a simple array of strings using the spring`s restTemplate. Did anyone succeed with that ?
The client:
public void save(){
String company = "12345";
String productId = "10";
String[] colors = {"A","B","C","D","E"};
String convertUrl = "http://localhost:8080/cool-web/save";
MultiValueMap<String, Object> convertVars = new LinkedMultiValueMap<String, Object>();
convertVars.add("companyID", StringUtils.trimToEmpty(company));
convertVars.add("productId", StringUtils.trimToEmpty(productId));
convertVars.add("disclaimer", StringUtils.trimToEmpty("ffs"));
convertVars.add("colorsArray", colors);
restTemplate.postForObject(convertUrl, null, String.class, convertVars);
}
The Service is:
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void save(@RequestParam("colorsArray[]") String[] colors,
@RequestParam("disclaimer") String disclaimer,
@RequestParam("companyID") String companyID,
@RequestParam("productId") String productId) {
resourceService.save(colors, disclaimer, companyID, productId);
}
I got 400 Bad Request.
What am I doing wrong ?
I am using the default messageConverters.
Do I need to implement custom messageConverter for a simple array of Strings ?