Przekazywanie mapy <String, String> do kontrolera springMVC
Próbuję wysłać HashMap lub inną implementację mapy z ajax do kontrolera Spring MVC
Oto szczegóły tego, jak to robię:
wywołanie Ajax jest następujące
var tags = {};
tags["foo"] = "bar";
tags["whee"] = "whizzz";
$.post("doTestMap.do", {"tags" : tags }, function(data, textStatus, jqXHR) {
if (textStatus == 'success') {
//handle success
console.log("doTest returned " + data);
} else {
console.err("doTest returned " + data);
}
});
potem po stronie kontrolera mam:
@RequestMapping(value="/publisher/doTestMap.do", method=RequestMethod.POST)
public @ResponseBody String doTestMap(@RequestParam(value = "tags", defaultValue = "") HashMap<String,String> tags, HttpServletRequest request) { //
System.out.println(tags);
return "cool";
}
Niestety systematycznie dostaję
org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map]: no matching editors or conversion strategy found
Co ja robię źle ?
Dziękuję Ci.