I am trying to convert following response with Retrofit 2
{
"errorNumber":4,
"status":0,
"message":"Gu00f6nderilen deu011ferler kontrol edilmeli",
"validate":[
"Daha u00f6nceden bu email ile kayu0131t olunmuu015f. Lu00fctfen giriu015f yapmayu0131 deneyiniz."
]
}
But I am allways getting null
response in onResponse
method. So I tried to look at error body of the response with response.errorBody.string()
. Error body contains exactly same content with raw response.
Here is my service method, Retrofit
object and response data declerations:
@FormUrlEncoded
@POST("/Register")
@Headers("Content-Type: application/x-www-form-urlencoded")
Call<RegisterResponse> register(
@Field("fullName") String fullName,
@Field("email") String email,
@Field("password") String password);
public class RegisterResponse {
public int status;
public String message;
public int errorNumber;
public List<String> validate;
}
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
final String content = UtilityMethods.convertResponseToString(response);
Log.d(TAG, lastCalledMethodName + " - " + content);
return response.newBuilder().body(ResponseBody.create(response.body().contentType(), content)).build();
}
});
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
domainSearchWebServices = retrofit.create(DomainSearchWebServices.class);
I have controlled response JSON
with jsonschema2pojo
to see if I modled my response class wright and it seems OK.
Why Retrofit fails to convert my response?
UPDATE
For now as a work around I am building my response from error body.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…