Hi everyone,
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp:logging-interceptor:2.6.0-SNAPSHOT'
Here is my Retrofit initialization (enabling OkHttp logging)
OkHttpClient client = new OkHttpClient();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
client.interceptors().add(interceptor);
// Initialize Retrofit
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://myendpoint.com")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
After executing this command of my API (which works fine on Postman)
@GET("data")
Call<JSONObject> getData();
The Response<JSONObject> reponse has an empty JSONObject on its response.body, which makes no sense even though OkHttp logging Interceptor was able to print the body data correctly.
The JSONObject type is from org.json.* not Gson. You want JsonObject from com.google.gson.*, or to bind to your own model class.
@JakeWharton Thank you very much :D
Most helpful comment
The
JSONObjecttype is fromorg.json.*not Gson. You wantJsonObjectfromcom.google.gson.*, or to bind to your own model class.