{"id":7854,"date":"2015-10-31T17:32:23","date_gmt":"2015-10-31T17:32:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/31\/retrofit-okhttp-gzip-ed-json-open-source-projects-square-okhttp\/"},"modified":"2015-10-31T17:32:23","modified_gmt":"2015-10-31T17:32:23","slug":"retrofit-okhttp-gzip-ed-json-open-source-projects-square-okhttp","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/31\/retrofit-okhttp-gzip-ed-json-open-source-projects-square-okhttp\/","title":{"rendered":"Retrofit + OkHttp + GZIP-ed JSON-open source projects square\/okhttp"},"content":{"rendered":"<p>I&#8217;m new to Retrofit but it seems really powerful. Everything works fine with a normal JSON, but as soon as I try a GZIPed one I just get an error:<\/p>\n<blockquote>\n<p>I\/System.out(14883): &#8212;&#8212;retrofit.RetrofitError: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1<\/p>\n<\/blockquote>\n<p>Obviously the the gibberish symbols I see in the Log cannot be parsed as JSON.<\/p>\n<p>I thought okHttp is catchig that gzip stuff correctly? What am I missing?<\/p>\n<p>These jars are in my libs folder:<\/p>\n<pre><code>retrofit-1.6.1.jar\nokhttp-2.0.0.jar\ngson-2.2.4.jar\n<\/code><\/pre>\n<p>This way I&#8217;m starting the call:<\/p>\n<pre><code>public interface OvlService {\n    @GET(\"\/gziptest.gz\")\n    void getOvls(Callback callback);\n}\n...\nOkHttpClient okHttpClient = new OkHttpClient();\nExecutor executor = Executors.newCachedThreadPool();\nRestAdapter restAdapter = new RestAdapter.Builder()\n.setEndpoint(\"http:\/\/my.domain\") \/\/ The base API endpoint.\n.setLogLevel(RestAdapter.LogLevel.FULL)\n.setExecutors(executor, executor)\n.setClient(new OkClient(okHttpClient))\n.build();\n\nOvlService ovlService = restAdapter.create(OvlService.class);\n\novlService.getOvls(new Callback() {\n\n    @Override\n    public void success(OvlWrapper arg0, Response arg1) {\n        System.out.println(\"result: \" + arg0.toString());\n    }\n});\n<\/code><\/pre>\n<p>The <code>result:<\/code>-line is never shown, but instead I see lots of these stuff <code>T\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd=\ufffdMk\ufffdA\ufffdG\ufffd4.\ufffd\ufffd@\ufffd\ufffdA\ufffd\ufffd<\/code> in the RetrofitLog. What do I do wrong that the gzip is not decompressed? Thanks!<\/p>\n<p><strong>Edit:<\/strong><\/p>\n<p>I tried it with a gzip file on my test server (<code>server.com\/ovl.gz<\/code>) and I also tried it with the original api server (<code>server2.com\/api.php?id=ovlgzip<\/code>). Same result, but different headers:<\/p>\n<p>Test server:<\/p>\n<pre><code>HTTP\/1.1 200 OK\nAccept-Ranges: bytes\nConnection: close\nContent-Length: 477\nContent-Type: application\/x-gzip\nETag: \"2cc40cb-1dd-...\"\nLast-Modified: Tue, 08 Jul 2014 17:00:08 GMT\nOkHttp-Received-Millis: 1404950522590\nOkHttp-Response-Source: NETWORK 200\nOkHttp-Selected-Transport: http\/1.1\nOkHttp-Sent-Millis: 1404950522533\nServer: Apache\n\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd}\ufffdQk\ufffd0\ufffd\ufffd\ufffd...\n<\/code><\/pre>\n<p>Original server:<\/p>\n<pre><code>HTTP\/1.1 200 OK\nConnection: Keep-Alive\nContent-Type: application\/json\nKeep-Alive: timeout=4, max=1000\nOkHttp-Received-Millis: 1404950697627\nOkHttp-Response-Source: NETWORK 200\nOkHttp-Selected-Transport: http\/1.1\nOkHttp-Sent-Millis: 1404950697002\nServer: Apache\nTransfer-Encoding: chunked\nX-Powered-By: PHP\/5.3.3-7+squeeze19\n\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd}\ufffdQk\ufffd0\ufffd\ufffd\ufffd...\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m new to Retrofit but it seems really powerful. Everything works fine with a normal JSON, but as soon as I try a GZIPed one I just get an error: I\/System.out(14883): &#8212;&#8212;retrofit.RetrofitError: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 Obviously the the gibberish symbols I see in the Log [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7854","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7854"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7854\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}