I call HTTP request with retrofit library and get results from an API. I configure log in retrofit library so i could see what's going on. The response is a simple primitive integer type. The problem is that it always returns zero. Response class(LoginModel) is also a classic class with one setter and one getter for integer type.
public class LoginModel {
@SerializedName("result")
private int result;
public void setResult(int result){
this.result = result;
}
public int getResult(){
return result;
}
}
Below image is my log which you can see i got response 10 but when i log getResult in onResponse function, it prints always zero.
Log.i("BODY : ", String.valueOf(response.body().getResult()));
I can't figure out whats wrong. I appreciate any help. thanks
UPDATE: full code of calling API
Call<LoginModel> isSended = apiService.sendCode(phoneNumber);
isSended.enqueue(new Callback<LoginModel>() {
@Override
public void onResponse(Call<LoginModel> call, Response<LoginModel> response) {
Log.i("BODY : ", String.valueOf(response.body().getResult()));
if (!response.isSuccessful()) {
Toast.makeText(context, context.getResources().getString(R.string.errorServer), Toast.LENGTH_LONG).show();
dismissProgressBarDialog();
return;
}
myTimer = new MyTimer(SECOND_TIME, 1000);
views.reactionActivationPress(response.body().getResult());
}
@Override
public void onFailure(Call<LoginModel> call, Throwable t) {
Log.i(Constant.NETWORK_LOG, "sendCode : " + t.toString());
dismissProgressBarDialog();
Toast.makeText(MyApplication.getContext(), "Server Problem", Toast.LENGTH_LONG).show();
}
});
from JSON response always returns zero for int value
No comments:
Post a Comment