title: Issue in getting json response data using Retrofit
body: <p>I am using Retrofit and having some issue in getting the data from response for the inner class.</p>
  
  <p><strong>DEPENDENCES:</strong></p>
  
  <pre><code>//// retrofit, gson
  implementation 'com.google.code.gson:gson:2.6.2'
  implementation 'com.squareup.retrofit2:retrofit:2.4.0'
  implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
  implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
  
  implementation 'com.android.support:recyclerview-v7:26.1.0'
  implementation 'com.github.bumptech.glide:glide:3.7.0'
  
  implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
  </code></pre>
  
  <p><strong>1. RetrofitClient :</strong></p>
  
  <pre><code>public class RetrofitClient {
  
  private static Retrofit retrofit = null;
  
  
   public static Retrofit getRetofitClient(String BaseUrl) {
      retrofit=null;
      if (retrofit == null) {
          retrofit = new Retrofit.Builder()
                  .baseUrl(BaseUrl)
                  .addConverterFactory(GsonConverterFactory.create())
                  .client(new OkHttpClient.Builder()
                          .addInterceptor(new LoggingInterceptor()).build())
                  .build();
      }
      return retrofit;
  }
  </code></pre>
  
  <p><strong>2. RetrofitListener :</strong> - my interface</p>
  
  <pre><code>public interface RetrofitListener&lt;T&gt;  {
   void handleSuccessResponse(T response,int type);
   void handleError(T error);}
  </code></pre>
  
  <p><strong>3. RequestParameters</strong> - my request parameter's class</p>
  
  <pre><code>public class RequestParameters {
  
  public static Map&lt;String,String&gt; login(String username,String password,String device_token,String device_type){
      Map&lt;String,String&gt; requestBody=new HashMap&lt;&gt;();
      requestBody.put("username",username);
      requestBody.put("password",password);
      requestBody.put("device_token",device_token);
      requestBody.put("device_type",device_type);
      return requestBody;
  }}
  </code></pre>
  
  <p><strong>4. ApiPresenter</strong> -my api presenter class</p>
  
  <pre><code>public class ApiPresenter {
  
  private RetrofitListener mListener;
  private ApiInterface mInterface;
  private Activity mActivity;
  public ProgressDialog p;
  
  public ApiPresenter(Activity activity,RetrofitListener listener,ApiInterface serviceInterface){
      this.mListener=listener;
      this.mInterface=serviceInterface;
      this.mActivity=activity;
  }
  
  public void showProgressDialog(){
      p=new ProgressDialog(mActivity);
      p.setMessage(mActivity.getResources().getString(R.string.strLoading));
      p.requestWindowFeature(Window.FEATURE_NO_TITLE);
      p.setCancelable(false);
      if(p!=null &amp;&amp; !p.isShowing()){
          p.show();
      }
  }
  
  public void dismissDialog(){
      if(p!=null &amp;&amp; p.isShowing()){
          p.dismiss();
      }
  }
  
  public Call&lt;User&gt; login(Map&lt;String,String&gt; params, final int requestCode, boolean isShowDialog){
  
      Log.e("PARAMS &gt;&gt; USERNAME : ",params.get("username"));
      Log.e("PARAMS &gt;&gt; PASSWORD :",params.get("password"));
  
      if(isShowDialog)
          showProgressDialog();
  
      Call&lt;User&gt; call = mInterface.login(params);
      call.enqueue(new Callback&lt;User&gt;() {
          @Override
          public void onResponse(Call&lt;User&gt; call, Response&lt;User&gt; response) {
              dismissDialog();
              if(mListener!=null){
                  mListener.handleSuccessResponse(response.body(),requestCode);
  
              }
          }
  
          @Override
          public void onFailure(Call&lt;User&gt; call, Throwable t) {
            dismissDialog();
            mListener.handleError(t.getMessage());
          }
      });
  
      return null;
  }
  public Call&lt;User&gt; signup(Activity activity, Map&lt;String, String&gt; params, final int requestCode, boolean isShowDialog) {
  
          if (isShowDialog) {
              showProgressDialog(activity);
          }
          Call&lt;SignUpModel&gt; userCall = apiService.signup(params);
          userCall.enqueue(new Callback&lt;SignUpModel&gt;() {
              @Override
              public void onResponse(Call&lt;SignUpModel&gt; call, Response&lt;SignUpModel&gt; response) {
  
                  dismisProgressDialog();
                  listener.handleSuccessResponse(response.body(), requestCode);
              }
  
              @Override
              public void onFailure(Call&lt;SignUpModel&gt; call, Throwable t) {
                  Log.e("Failure", "==" + t.getMessage());
                  dismisProgressDialog();
                  listener.handleErrorResponse(t.getMessage());
              }
          });
  
          return null;
      }
      public Call&lt;ResultData&gt; getResults(Activity activity, String input,String format, final int requestCode, boolean isShowDialog) {
  
          if (isShowDialog) {
              showProgressDialog(activity);
          }
          Call&lt;ResultData&gt; userCall = apiService.getVin(input,format);
          userCall.enqueue(new Callback&lt;ResultData&gt;() {
              @Override
              public void onResponse(Call&lt;ResultData&gt; call, Response&lt;ResultData&gt; response) {
  
                  dismisProgressDialog();
                  listener.handleSuccessResponse(response.body(), requestCode);
              }
  
              @Override
              public void onFailure(Call&lt;ResultData&gt; call, Throwable t) {
                  Log.e("Failure", "==" + t.getMessage());
                  dismisProgressDialog();
                  listener.handleErrorResponse(t.getMessage());
              }
          });
  
          return null;
      }
  }}
  </code></pre>
  
  <p><strong>5.User.java</strong> -my model class</p>
  
  <pre><code>public class User {
      private Integer status;
      private Data data;
      private String message;
  
      public Integer getStatus() {
          return status;
      }
      public void setStatus(Integer status) {
          this.status = status;
      }
      public Data getData() {
          return data;
      }
      public void setData(Data data) {
          this.data = data;
      }
      public String getMessage() {
          return message;
      }
      public void setMessage(String message) {
          this.message = message;
      }
      class Data {
          @SuppressLint("id")
          private String id;
          @SuppressLint("first_name")
          private String firstName;
          @SuppressLint("last_name")
          private String lastName;
          @SuppressLint("email")
          private String email;
          @SuppressLint("username")
          private String username;
          @SuppressLint("password")
          private String password;
          @SuppressLint("photo")
          private String photo;
          @SuppressLint("birthdate")
          private String birthdate;
          @SuppressLint("gender")
          private String gender;
          @SuppressLint("token")
          private String token;
          @SuppressLint("device_type")
          private String deviceType;
          private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
          public String getId() {
              return id;
          }
          public void setId(String id) {
              this.id = id;
          }
          public String getFirstName() {
              return firstName;
          }
          public void setFirstName(String firstName) {
              this.firstName = firstName;
          }
          public String getLastName() {
              return lastName;
          }
          public void setLastName(String lastName) {
              this.lastName = lastName;
          }
          public String getEmail() {
              return email;
          }
          public void setEmail(String email) {
              this.email = email;
          }
          public String getUsername() {
              return username;
          }
          public void setUsername(String username) {
              this.username = username;
          }
          public String getPassword() {
              return password;
          }
          public void setPassword(String password) {
              this.password = password;
          }
          public String getPhoto() {
              return photo;
          }
          public void setPhoto(String photo) {
              this.photo = photo;
          }
          public String getBirthdate() {
              return birthdate;
          }
          public void setBirthdate(String birthdate) {
              this.birthdate = birthdate;
          }
          public String getGender() {
              return gender;
          }
          public void setGender(String gender) {
              this.gender = gender;
          }
          public String getToken() {
              return token;
          }
          public void setToken(String token) {
              this.token = token;
          }
          public String getDeviceType() {
              return deviceType;
          }
          public void setDeviceType(String deviceType) {
              this.deviceType = deviceType;
          }
      }}
  </code></pre>
  
  <p><strong>6. Calling</strong> -- calling login service on button click</p>
  
  <pre><code>public void login(View view) {
  
      if(isNetworkConnected(MainActivity.this)){
          new ApiPresenter(MainActivity.this,this,apiService)
                  .login( RequestParameters.login("jaimin","123456","devicetoken","0"),CODE_LOGIN,true);
      }else{
          Toast.makeText(this, ""+getResources().getString(R.string.toast_check_internet), Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p><strong>7. My HandleResponse method</strong> -- override method of interface</p>
  
  <pre><code>@Override
  public void handleSuccessResponse(Object response, int type) {
      switch(type){
          case CODE_REGISTER_USER:
  
              if (response instanceof UserModel)
                  handleResponseCatAssignProductList((UserModel) response);
  
              break;
  
          case CODE_LOGIN:
              if(response instanceof User){
                  handleLoginREsponse((User)response);
              }
              break;
  
          case CODE_SIGNUP:
              if(response instanceof SignUpModel){
                  handleSignupREsponse((SignUpModel)response);
              }
              break;
      }
  }
  </code></pre>
  
  <p><strong>8. APISERVICE</strong></p>
  
  <pre><code>public interface ApiService {
  
  @FormUrlEncoded
  @POST("webservice/login")
  Call&lt;User&gt; login(@FieldMap Map&lt;String, String&gt; params);
  
  @FormUrlEncoded
  @POST("webservice/signup")
  Call&lt;UserModel&gt; register(@FieldMap Map&lt;String, String&gt; params);
  
  @Headers("Authorization:U2FsdGVkX1+2uAhde5/Z1w/k=")
  @POST("customerRegistration.php")
  Call&lt;SignUpModel&gt; signup(@Body Map&lt;String,String&gt; params);
  
  @GET("/api/vehicles/DecodeVinValues/{input}")
  Call&lt;ResultData&gt; getVin(@Path("input") String input, @Query("format") String format);
  
  @GET("FlowersList.php")
  Call&lt;JsonArray&gt; getFlower();}
  </code></pre>
  
  <p><strong>ISSUE :</strong> I am getting response. But, Data is getting null. In response I am getting, <strong>Please provide username and password.</strong></p>
  
  <p>In logcat, am getting : </p>
  
  <pre><code>10-12 14:42:42.436 3387-3387/com.example.jaimin.retrofitcommondemo E/PARAMS &gt;&gt; USERNAME :: jaimin
      10-12 14:42:42.436 3387-3387/com.example.jaimin.retrofitcommondemo E/PARAMS &gt;&gt; PASSWORD :: 123456
      10-12 14:47:06.788 3387-3387/com.example.jaimin.retrofitcommondemo E/&lt;&lt;&lt;&lt;&lt;&lt;&lt; response: &gt;&gt;User and password could not be null
  </code></pre>
  
  <p>What might be the issue?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><strong>my JSON String :</strong></p>
  
  <pre><code>{
     "status":1,
     "data":{
        "id":"591",
        "first_name":"jaimin",
        "last_name":"modi",
        "email":"test12@gmail.com",
        "username":"jaimin",
        "password":"e1ba59abbe56e057f20f883e",
        "photo":"http:temp.jpg",
        "birthdate":"1992-12-24",
        "gender":"",
        "token":"dsfsf",
        "device_type":"0"
     },
     "message":"Successful Login"
  }
  </code></pre>
  
  <p><strong>9. LOGGING INTERCEPTOR</strong></p>
  
  <pre><code>public class LoggingInterceptor implements Interceptor {
  @Override
  public Response intercept(Interceptor.Chain chain) throws IOException {
      Request request = chain.request();
      Response response = chain.proceed(request);
      final String responseString = new String(response.body().bytes());
      Log.e("REsponse", "Response: " + responseString);
      return response.newBuilder()
              .body(ResponseBody.create(response.body().contentType(), responseString))
              .build();
  }}
  </code></pre>