I have a problem with Retrofit & Android.
I have API method "api/account/login". This method has Content-Type application/json and what about the body:
"Request body has to contain LoginData object serialized to JSON format and properly encrypted" (from api doc) So, sample body:
"cUdu2LkEChP...Lw7R9m4="
Also, I have second API Method: "api/account/data", which have the same body and content-type.
What is my problem? I am using Retrofit to connect with API.
interface APIService {
@POST("api/account/login")
void postLogin(@Body String encryptedCredentials, Callback<String> callback);
@POST("/api/account/data")
void postLoginData(@Body String encryptedCredentials, Callback<String> response);
}
for first method everything works fine, API returns what should return, but, for the second method Retrofit returns error:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 2 path $
Actually now I have no idea what is going on, both methods take the same body, but only one is failing...
handling api-calls:
@Override
// THIS WORKS FINE!
public APIRequest postLoginRequest(final String encryptedCredentials) {
return new APIRequest() {
@Override
protected void fireRequest() {
APIServiece.postLogin(encryptedCredentials, new Callback<String>() {
@Override
public void success(String s, Response response) {
logicEventBus.post(new LoginEvent(null, s));
}
@Override
public void failure(RetrofitError error) {
logicEventBus.post(new LoginEvent(error, null));
}
});
}
};
}
@Override
// THIS DOESNT WORK FINE :(
public APIRequest postLoginDataRequest(final String encryptedCredentials, final AccountData.LoggedBy loggedBy) {
return new APIRequest() {
@Override
protected void fireRequest() {
Callback<String> callback = new Callback<String>() {
@Override
public void success(String s, Response response) {
logicEventBus.post(new LoginDataEvent(null, s));
}
@Override
public void failure(RetrofitError error) {
logicEventBus.post(new LoginDataEvent(error, null));
}
};
switch (loggedBy) {
case INTERNAL:
APIService.postLoginData(encryptedCredentials, callback);
break;
case FACEBOOK:
APIService.postLoginData(encryptedCredentials, callback);
break;
case GOOGLEPLUS:
APIService.postLoginData(encryptedCredentials, callback);
break;
}
}
};
}
I have checked in the debugger, strings are fine. API also works fine (checked in Postman). Debugger never get into "success" (in not-working method).
Thanks for any kind of help!