The REST service I want to consume answers as a gzipped encoded JSON. It provides the Content-Encoding: gzip
, but my OkHttp does not encode it to readable text, so the JSON converter throws an exception.
According to Jake Whartons comment the Content-Encoding: gzip
Header should tell OkHttp to decode the body.
The code for creating the RestAdapter is:
final RestAdapter adapter = new RestAdapter.Builder() .setEndpoint(baseUrl) .setClient(new OkClient(new OkHttpClient())) .setConverter(new GsonConverter(gson)) .setLogLevel(RestAdapter.LogLevel.FULL) .build(); service = adapter.create(RaplaService.class);
The gradle dependencies are:
compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.okhttp:okhttp:2.6.0'
The method in my ServiceInterface:
@Headers({ "Accept-Encoding: gzip, deflate", "Content-Type: application/json;charset=utf-8", "Accept: application/json" }) @GET("/events") List getEvents(@Header("Authorization") String token, @Query("resources") String resources, @Query("start") String start, @Query("end") String end);