I am using Spring's Rest Template to post a request with data to a web service. Here is my client code snippet-
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, RequestDefinition> map = new LinkedMultiValueMap<String, RequestDefinition>();
map.add("requestJSON", someDataObject);
MappingJackson2HttpMessageConverter jsonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
restTemplate.getMessageConverters().add(jsonHttpMessageConverter);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
restTemplate.postForObject(someUrl, map, String.class);
Here is my servet code post method-
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String reqJSONStr = (String) request.getParameter("requestJSON");
// reqJSONStr is coming as null. No idea why
// some other logic follows here
}
The problem is, in my servlet post method, the requestJSON object is coming as null. Can somebody please point out the mistake I am doing here.