title: send json data through a post call by using rest template from spring
body: <p>I keep getting an error saying that this is not valid json data and keep getting error 400. I don't think the implementation I have is formatting data properly. 
  Goal: trying to make a post call using a rest template, by passing in JSON data as the body. It seems that when converting from map to json data, it isn't properly converted to json.</p>
  
  <pre><code>public void GetJsonData(String name, String city) {
          Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          map.put("api_key", apikey);
  
  
  
  map.put("venue_queries", "[{'name':'"+name+"', 'location': {'locality': '"+city+"'}}]");
  
          try {
              String resp = GlobalHelper.calltestService(RestServicesUrl, map);
              System.out.println(resp);
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  
  
  public String calltestService(String url, Map&lt;String, String&gt; data) throws Exception {
          RestTemplate rest = new RestTemplate();
          HttpHeaders headers = new HttpHeaders();
          headers.setContentType(MediaType.APPLICATION_JSON);
          headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
          ResponseEntity&lt;String&gt; response = new ResponseEntity&lt;String&gt;(headers, HttpStatus.OK);
          rest.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
              Gson gson = new Gson();
              System.out.println(gson.toJson(data));
          try {
              response = rest.postForEntity(url, gson.toJson(data), String.class);
              System.out.println(response.getBody()); 
              System.out.println(response.getHeaders());
              return response.getBody();
          } catch (Exception e) {
              e.printStackTrace();
              System.out.println("error in post entity");
              return "error";
          }
      }
  </code></pre>