In Spring Rest , I have a RestController exposing this method:
@RestController
@RequestMapping("/controllerPath")
public class MyController{
@RequestMapping(method = RequestMethod.POST)
public void create(@RequestParameter("myParam") Map<String, String> myMap) {
}
}
I want to test this method using MockMVC from Spring :
Map<String, String> myMap = init();
ObjectMapper mapper = new ObjectMapper();
String jsonMap = mapper.writeValueAsString(myMap);
mockMvc.perform(post("/controllerPath")
.param("myParam", jsonMap)
.andExpect(status().isOk());
The problem is that I received a 500 HTTP error code . I am pretty sure that this is due to the fact that I use Map as a parameter of my controller (I tried changing it to String, and it works).
The question is how to make the Map in parameter be in my RestController and correctly test it with MockMVC ?
Thanks for any help.