I am using Retrofit2 for all the network calls in my android application. Im configuring a POJO for a particular response. But I want to just check the raw Json repsonse for some extra response which is not included as a variable in POJO.
POJO
public class User {
@SerializedName("user_id")
private long userId;
@SerializedName("user_name")
private String userName;
@SerializedName("hobbies")
private String hobbies;
@SerializedName("class")
private String studyClass;
@SerializedName("branch_id")
private long branchId;
@SerializedName("createdOn")
private Date createdOn;
}
My network interface
public interface ApiInterface {
@GET("user/{userId}")
Call<User> getUserInfo(@Path("userId") long userId);
}
My code for requesting the data .
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
ApiInterface apiService = retrofit.create(ApiInterface.class);
Call<User> call = apiService.getUserInfo(userId);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
User user = response.body();
setViews(user);
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Toast.makeText(getApplicationContext(), "On failure while requesting server", Toast.LENGTH_LONG).show();
}
});
How to check the raw response . But I want the interface method to return the POJO.