Retrofit, response body always null but on server is status 200

1

I am implementing an Android application using Retrofit 2, the service is generic the server side is working.

The problem is: The response.body () is always null, I can never get json, even though I can print it with OKHTTP.

How to solve this problem or get the json 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);

(...)
}
    
asked by anonymous 20.11.2016 / 12:13

1 answer

0

I found the answer, it was a simple mistake. The ServiveGenerator was built to wait for a response from a list, it was only to change the build of the request and everything worked correctly.

RetrofitServices

    public interface RetrofitServicePost {

        @FormUrlEncoded
        @GET("tipoalerta")
        Call<List<TipoAlerta>> getListaTipoAlerta();

        @FormUrlEncoded
        @GET("tipoalerta/id/{id}")
        Call<List<TipoAlerta>> getTipoAlerta(@Path("id") String id);

    (...)
    }
    
21.11.2016 / 10:47