title: Retrofit 2 - Is it possible to get the size of a JSON that I'm sending and receiving?
body: <p>I need to build a traffic monitor on my Android app, and I need to have stored the size of all json that I'm sending and receiving through retrofit. Using log I can see the actual size of it, but I haven't find a way to get this information so I could save it. I can't get the response.raw either since it's already been parsed to my classes. Is there any way to achieve that? </p>
  
  <p>EDIT: Marked vadkou answer as the best one.</p>
  
  <p>Instead of creating a new interceptor, I passed the lamda expression:</p>
  
  <pre><code> httpClient.addInterceptor( chain -&gt; {
          okhttp3.Request request = chain.request();
          okhttp3.Response response = chain.proceed(request);
          if(request.body()!=null) {
              long requestLength = request.body().contentLength();
              Log.e("SERVICE GENERATOR", " CONTENT LENGTH" + requestLength);
  
          }
          long responseLength = response.body().contentLength();
          Log.e("SERVICE GENERATOR", " RESPONSE LENGTH" + responseLength);
  
          return response;
  
      });
  </code></pre>