I'm getting the following error in org.springframework.web.client.RestClientException: No HttpMessageConverter for java.util.HashMapwhen using rest template. Does anyone have any idea whats wrong?
Using java 1.8, spring 5.2.2, commons-logging 1.2.
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.client.RestTemplate;
public class testapi {
   private static final String API_BASE_URL = "https://xyz/rest/ng";
   private static RestTemplate template = new RestTemplate();
public static void main(String[] args)
   throws Exception {
String token = login();
}
 private static String login() {
       Map<String, Object> payload = new HashMap<>();
       payload.put("loginName", "abc.com");
          payload.put("password", "xyz");
          Map<String, Object> resp = template.postForObject(getUrl("/sessions"), payload, Map.class);
          return (String) resp.get("token");
            }
}
Error
Exception in thread "main" org.springframework.web.client.RestClientException: No HttpMessageConverter for java.util.HashMap
    at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:964)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677)
    at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:421)
    at TestFormApis.login(testapis.java:117)
    at TestFormApis.main(testapis.java:61)
 
                        
Run the app as Spring one and do the conversion using the code below. I had to include the jackson-core-2.2.0-rc1.jar libs to my project as well.