title: Retrofit 2.0.1 Post JSON -- MalformedJsonException
body: <p>I am having troubles doing a POST request with retrofit 2. I am attempting to POST using Retrofit's GsonConverterFactory to convert a POJO object into JSON. </p>
  
  <p>I have GET requests to work with the GsonConverterFactory converting the body into a POJO class, but on a POST it doesn't seem to work (POJO to JSON). I am using this in Android Studio and use Gradle to build my project. These are my Gradle dependencies:</p>
  
  <pre><code>compile 'com.squareup.retrofit2:retrofit:2.0.1'
  compile 'com.squareup.okhttp:okhttp:2.7.5'
  compile 'com.google.code.gson:gson:2.6.2'
  compile 'com.squareup.retrofit2:converter-gson:2.0.1'
  </code></pre>
  
  <p>Here is my code for the Api Interface:</p>
  
  <pre><code>public interface EhabrApi {
      @POST("/create-account")
      Call&lt;ResponseBody&gt; createUser(@Body User user);
  }
  </code></pre>
  
  <p>And this is the code to make the request:</p>
  
  <pre><code>    User newUser = new User("Bob", "Smith", "bob@gmail.com", "password", "Seattle", "1990-01-01");
  
      System.out.println("User is " + new Gson().toJson(newUser));
  
      Retrofit retrofit = new Retrofit.Builder()
              .baseUrl(API_URL)
              .addConverterFactory(GsonConverterFactory.create())
              .build();
  
      EhabrApi ehabrApi = retrofit.create(EhabrApi.class);
      Call&lt;ResponseBody&gt; call = ehabrApi.createUser(newUser);
      System.out.println("Request is " + new Gson().toJson(call.request()));
  
      call.enqueue(new Callback&lt;ResponseBody&gt;() {
             @Override
             public void onResponse(Call&lt;ResponseBody&gt; call, Response&lt;ResponseBody&gt; response) {
                 int statusCode = response.code();
                 System.out.println("Recieved " + statusCode);
             }
  
             @Override
             public void onFailure(Call&lt;ResponseBody&gt; call, Throwable t) {
                 System.out.println("Failed call " + t);
                 System.out.println("stack trace: ");
                 t.printStackTrace();
             }
          }
      );
  </code></pre>
  
  <p>Here is my output and the stack trace:</p>
  
  <pre><code>Creating new account
  User is {"Birthday":"1990-01-01","City":"Seattle","Email":"bob@gmail.com","FirstName":"Bob","LastName":"Smith","Password":"password"}
  Request is {"headers":{"namesAndValues":[]},"method":"POST","url":{"host":"mywebpage.com","password":"","pathSegments":["create-account"],"port":8080,"scheme":"http","url":"http://mywebpage.com","username":""}}
  Failed call com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
  stack trace: 
  com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
      at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1567)
      at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1416)
      at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:597)
      at com.google.gson.stream.JsonReader.peek(JsonReader.java:429)
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:201)
      at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
      at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
      at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:116)
      at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
      at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106)
      at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
      at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
      at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Now I have put in an interceptor as suggested. The POST request looks right to me... Here it is:</p>
  
  <pre><code>--&gt; POST http://[mywebpageurl.com]/create-account http/1.1
  Content-Type: application/json; charset=UTF-8
  Content-Length: 125
  {"Birthday":"1990-01-01","City":"Seattle","Email":"bob@gmail.com","FirstName":"Bob","LastName":"Smith","Password":"password"}
  --&gt; END POST (125-byte body)
  &lt;-- 200 OK http://[mywebpageurl.com]/create-account (100ms)
  </code></pre>