1
I am implementing an Android application using Retrofit 2, the service is generic the server side is working.
The problem is: Response.body() is always null, I can never catch json, even if I can print it with OKHTTP.
How to solve this problem or get json straight from okhttp?
Servicegenerator
public class ServiceGenerator {
public static <S> S createService(Class<S> serviceClass) {
//Instancia do interceptador das requisições
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
.readTimeout(15, TimeUnit.SECONDS);
httpClient.addInterceptor(loggingInterceptor);
//Instância do retrofit
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create(new Gson()))
.client(httpClient.build())
.build();
return retrofit.create(serviceClass);
}
}
Retrofirservicespost
public interface RetrofitServicePost {
@FormUrlEncoded
@GET("tipoalerta")
Call<List<TipoAlerta>> getListaTipoAlerta();
@GET("tipoalerta/id/{id}")
Call<TipoAlerta> getTipoAlerta(@Path("id") String id);
(...)
}