title: Rails/Devise - Unprocessable Entity
body: <p>I am trying to use a post request (JSON) to create a user. The example with curl works fine. Here is the curl command: </p>
  
  <pre><code>curl -X POST -H "Content-Type: application/json" 'http://localhost:3000/users.json' -d '{ "user": {"email": "e@f.com", "password": "foobar", "password_confirmation": "foobar"}}'
  </code></pre>
  
  <p><strong>curl output:</strong> </p>
  
  <pre><code>Started POST "/users.json" for 127.0.0.1 at 2012-01-28 16:19:10 -0800
    Processing by Devise::RegistrationsController#create as JSON
    Parameters: {"user"=&gt;{"email"=&gt;"e@f.com", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]"}}
  </code></pre>
  
  <p>but when I try a request with http libraries in java I get an error: </p>
  
  <pre><code>Started POST "/users.json" for 192.168.1.88 at 2012-01-28 16:47:56 -0800
    Processing by Devise::RegistrationsController#create as JSON
    Parameters: {"user"=&gt;"{\"password_confirmation\":\"secret\",\"password\":\"secret\",\"email\":\"a@foo.com\"}"}
  Completed 422 Unprocessable Entity in 73ms (Views: 3.0ms | ActiveRecord: 0.0ms)
  </code></pre>
  
  <p>The code for creating the request: </p>
  
  <pre><code>            RestClient client = new RestClient(SIGNUP_URL);
              JSONObject jObj = new JSONObject();
              JSONObject jsonUserObj = new JSONObject();
  
              try {
                  jObj.put("email", txtUserName.getText().toString());
                  jObj.put("password", txtPassword.getText().toString());
                  jObj.put("password_confirmation", txtPassword.getText().toString());
  
                  jsonUserObj.put("user", jObj.toString());
              } catch (JSONException e1) {
                  e1.printStackTrace();
              }
  
              client.setJSONParams(jsonUserObj);
              try {
                  client.Execute(RequestMethod.JSON_POST);
              } catch (IOException e) {
                  e.printStackTrace();
              } catch (JSONException e) {
                      e.printStackTrace();
              } catch (Exception e) {
                      e.printStackTrace();
              }   
              if (client.getResponseCode() == HttpStatus.SC_OK) {
                 // Good response
                 try {
                     jObj = new JSONObject(client.getResponse());
                     System.out.println("Signup Successful");
                 } catch (JSONException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                 }
              }
          }
  </code></pre>
  
  <p>Here is the function that is called for execute: </p>
  
  <pre><code>    HttpPost request = new HttpPost(url);
              request.addHeader("Content-Type", "application/json");
              request.addHeader("Accept", "application/json");
              StringEntity s = new StringEntity(jsonParams.toString(), HTTP.UTF_8);
              s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
              request.setEntity(s);
              executeRequest(request, url);
              break;
  </code></pre>