{"id":7889,"date":"2015-11-05T11:27:39","date_gmt":"2015-11-05T11:27:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/05\/retrofit-callback-get-response-body-open-source-projects-square-retrofit\/"},"modified":"2015-11-05T11:27:39","modified_gmt":"2015-11-05T11:27:39","slug":"retrofit-callback-get-response-body-open-source-projects-square-retrofit","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/05\/retrofit-callback-get-response-body-open-source-projects-square-retrofit\/","title":{"rendered":"Retrofit callback get response body-open source projects square\/retrofit"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/aQvkj.png?s=128&amp;g=1\" \/> <strong>Michael Alan Huff<\/strong><\/p>\n<p>I recently encountered a similar problem. I wanted to look at some json in the response body but didn&#8217;t want to deal with the TypedByteArray from Retrofit. I found the quickest way to get around it was to make a Pojo(Plain Old Java Object) with a single String field. More Generally you would make a Pojo with one field corresponding to whatever data you wanted to look at.<\/p>\n<p>For example, say I was making a request in which the response from the server was a single string in the response&#8217;s body called &#8220;access_token&#8221;<\/p>\n<p>My Pojo would look like this:<\/p>\n<pre><code>public class AccessToken{\n    String accessToken;\n\n    public AccessToken() {}\n\n    public String getAccessToken() {\n        return accessToken;\n    }\n} \n<\/code><\/pre>\n<p>and then my callback would look like this<\/p>\n<pre><code>Callback callback = new Callback() {\n   @Override\n   public void success(AccessToken accessToken, Response response) {\n       Log.d(TAG,\"access token: \"+ accessToken.getAccessToken());\n   }\n\n   @Override\n   public void failure(RetrofitError error) {\n       Log.E(TAG,\"error: \"+ error.toString());\n   }\n};\n<\/code><\/pre>\n<p>This will enable you to look at what you received in the response.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Michael Alan Huff I recently encountered a similar problem. I wanted to look at some json in the response body but didn&#8217;t want to deal with the TypedByteArray from Retrofit. I found the quickest way to get around it was to make a Pojo(Plain Old Java Object) with a single String field. More Generally you [&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-7889","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7889","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=7889"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7889\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}