title: Spring-android RestTemplate post fail
body: <p><strong>PROBLEM</strong></p>
  
  <p>I'm thinking of converting my existing http post method to <code>spring-android</code> but I failed.</p>
  
  <pre><code>JSONObject defaultJsonObject = new JSONObject();
  defaultJsonObject.put("ln", "Kiat");
  defaultJsonObject.put("CountryName", "Malaysia");
  defaultJsonObject.put("CityName", "Kuala Lumpur");
  </code></pre>
  
  <p>This is my existing http post which is working and will form a post body as : <code>[json={"ln":"Kiat","CountryName":"Malaysia","CityName":"Kuala Lumpur"}]</code></p>
  
  <pre><code>List&lt;NameValuePair&gt; postParams = new ArrayList&lt;NameValuePair&gt;();
   postParams.add(new BasicNameValuePair("json", jsonObject.toString()));
   UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams);
   System.out.println("post param: " + postParams.toString());
   post.setEntity(entity);
   post.setHeader("Accept", "application/json");
  </code></pre>
  
  <p>but when I convert to Spring-android with RestTemplate it failed. Even I already managed to form the post body as <code>[json={"ln":"Kiat","CountryName":"Malaysia","CityName":"Kuala Lumpur"}]</code>  I keep getting  500 Internal Server Error</p>
  
  <pre><code>HttpHeaders requestHeaders = new HttpHeaders();
  requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
  List&lt;NameValuePair&gt; postParams1 = new ArrayList&lt;NameValuePair&gt;();
  postParams1.add(new BasicNameValuePair("json", jsonObject.toString()));
  HttpEntity&lt;?&gt; requestEntity = new HttpEntity&lt;Object&gt;(postParams1, requestHeaders);
  RestTemplate restTemplate = new RestTemplate();
  restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
  restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
  ResponseEntity&lt;String&gt; response = restTemplate.exchange(url, HttpMethod.POST, requestEntity,String.class)
  </code></pre>
  
  <p>The post body format will be something like this </p>
  
  <p>[json={"ln":"Kiat","CountryName":"Malaysia","CityName":"Kuala Lumpur"}]</p>