title: Retrofit 2 return response data object for further use
body: <p>I use POJO and Retrofit2 in Android to call a REST service to get some data. I do receive the data in response.body() as expected but I do not want this data to be assigned to any android UI component. I want to get this returned object and return back or work outside of the onResponse.</p>
  
  <p>Sorry I am new to JAVA or callbacks but on searching found that I need to write callback but not sure how to write it. Can someone please help. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>public String getUserIPCountry(Context context){       
  
      ipf = new Ipinfo();
  
      IpinfoAPI.Factory.getInstance().getCountryCode().enqueue(new Callback&lt;Ipinfo&gt;() {
          @Override
          public void onResponse(Call&lt;Ipinfo&gt; call, Response&lt;Ipinfo&gt; response) {
  
              if(response.isSuccessful()){
  
                 //Want to return/use below data outside of this method
                 //response.body().getCountryCode();
              }
          }
  
          @Override
          public void onFailure(Call&lt;Ipinfo&gt; call, Throwable t) {
  
          }
      });
  
      return null;
  }    
  </code></pre>