retrofit 2.0 how to print the full json response?

To print the full response in json:

Log.w("2.0 getFeed > Full json res wrapped in gson => ",new Gson().toJson(response));

If you’d like to have pretty print feature, use:

Log.w("2.0 getFeed > Full json res wrapped in pretty printed gson => ",new GsonBuilder().setPrettyPrinting().create().toJson(response));

Note that this prints the deserialized data (not raw response as returned from server). To get the raw response, you may use one of these:

  1. Use HttpLoggingInterceptor see: https://stackoverflow.com/a/33256827/2267723 or have your own version of interceptor
  2. Use http debugging tools such Stetho. see: http://facebook.github.io/stetho/ or Charles Web Debugging Proxy. see: https://www.charlesproxy.com

Leave a Comment