title: Could not write request: no suitable HttpMessageConverter found for request type [org.json.JSONObject] and content type [application/json]
body: <p>I'm digging myself in trying to send a POST request with a JSON payload to a remote server.</p>
  
  <p>This GET curl command works fine:</p>
  
  <pre><code>curl -H "Accept:application/json" --user aaa@aaa.com:aaa "http://www.aaa.com:8080/aaa-project-rest/api/users/1" -i
  </code></pre>
  
  <p>And this POST one works fine too:</p>
  
  <pre><code>curl -H "Accept:application/json" -H "Content-Type: application/json" "http://www.aaa.com:8080/aaa-project-rest/api/users/login" -X POST -d "{ \"email\" : \"aaa@aaa.com\", \"password\" : \"aaa\" }" -i
  </code></pre>
  
  <p>And so I'm trying to mimic it in my Android app.</p>
  
  <p>The app works fine on the first GET request but gives a 400 Bad Request on the second POST one.</p>
  
  <p>Here is the code that works for the GET request:</p>
  
  <pre><code>  RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    HttpHeaders httpHeaders = Common.createAuthenticationHeaders("aaa@aaa.com" + ":" + "aaa");
    User user = null;
    ResponseEntity&lt;User&gt; responseEntity = restTemplate.exchange("http://" + REST_HOST + ":8080/aaa-project-rest/api/users/" + 1L, HttpMethod.GET, new HttpEntity&lt;Object&gt;(httpHeaders), User.class);
  </code></pre>
  
  <p>Here is the source code for the POST request:</p>
  
  <pre><code>RestTemplate restTemplate = new RestTemplate();
  restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
  User user = null;
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(MediaType.APPLICATION_JSON);
  httpHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
  JSONObject jsonCredentials = new JSONObject();
  jsonCredentials.put("email", REST_LOGIN);
  jsonCredentials.put("password", REST_PASSWORD);
  ResponseEntity&lt;User&gt; responseEntity = restTemplate.exchange("http://" + REST_HOST + ":" + REST_PORT + "/" + REST_APP + "/api/users/login",
          HttpMethod.POST, new HttpEntity&lt;Object&gt;(jsonCredentials, httpHeaders), User.class);
  </code></pre>
  
  <p>But it gives the message:</p>
  
  <pre><code>Could not write request: no suitable HttpMessageConverter found for request type [org.json.JSONObject] and content type [application/json]
  </code></pre>
  
  <p>Here is the Spring REST controller:</p>
  
  <pre><code>@RequestMapping(value = RESTConstants.SLASH + RESTConstants.LOGIN, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public ResponseEntity&lt;UserResource&gt; login(@Valid @RequestBody CredentialsResource credentialsResource, UriComponentsBuilder builder) {
      HttpHeaders responseHeaders = new HttpHeaders();
      User user = credentialsService.checkPassword(credentialsResource);
      userService.clearReadablePassword(user);
      if (user == null) {
          return new ResponseEntity&lt;UserResource&gt;(responseHeaders, HttpStatus.NOT_FOUND);
      } else {
          tokenAuthenticationService.addTokenToResponseHeader(responseHeaders, credentialsResource.getEmail());
          responseHeaders.setLocation(builder.path(RESTConstants.SLASH + RESTConstants.USERS + RESTConstants.SLASH + "{id}").buildAndExpand(user.getId()).toUri());
          UserResource createdUserResource = userResourceAssembler.toResource(user);
          ResponseEntity&lt;UserResource&gt; responseEntity = new ResponseEntity&lt;UserResource&gt;(createdUserResource, responseHeaders, HttpStatus.CREATED);
          return responseEntity;
      }
  }
  
  @RequestMapping(value = RESTConstants.SLASH + "{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public ResponseEntity&lt;UserResource&gt; findById(@PathVariable Long id, UriComponentsBuilder builder) {
      HttpHeaders responseHeaders = new HttpHeaders();
      User user = userService.findById(id);
      if (user == null) {
          return new ResponseEntity&lt;UserResource&gt;(responseHeaders, HttpStatus.NOT_FOUND);
      } else {
          UserResource userResource = userResourceAssembler.toResource(user);
          responseHeaders.setLocation(builder.path(RESTConstants.SLASH + RESTConstants.USERS + RESTConstants.SLASH + "{id}").buildAndExpand(user.getId()).toUri());
          ResponseEntity&lt;UserResource&gt; responseEntity = new ResponseEntity&lt;UserResource&gt;(userResource, responseHeaders, HttpStatus.OK);
          return responseEntity;
      }
  }
  </code></pre>
  
  <p>The CredentialsResource class code:</p>
  
  <pre><code>public class CredentialsResource extends ResourceSupport {
  
      @NotEmpty
      @Email
      private String email;
      @NotEmpty
      private String password;
  
      public CredentialsResource() {
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
  }
  </code></pre>