title: Android:dynamically pass model class to retrofit callback
body: <p>In retrofit to map json response to pojo usually we do this  </p>
  
  <pre><code>@POST
  Call&lt;User&gt; getDataFromServer(@Url String url, @Body HashMap&lt;String,Object&gt; hashMap);
  
  ApiCalls api = retrofit.create(ApiCalls.class);
      Call&lt;User&gt; call = api.getDataFromServer(StringConstants.URL,hashMap);
      call.enqueue(new Callback&lt;User&gt;() {
           //Response and failure callbacks
      }
  </code></pre>
  
  <p>where User is my Pojo class.
  But for every other request i need to make different pojo and write same code for retrofit call.I want to make a single method for calling api and pass the respective pojo class to retrofit call. like this</p>
  
  <pre><code>ApiCalls api = retrofit.create(ApiCalls.class);
  Call&lt;*ClassPassed*&gt; call = api.getDataFromServer(StringConstants.URL,hashMap);
  call.enqueue(new Callback&lt;*ClassPassed*&gt;() {
       //Response and failure callbacks
  }
  </code></pre>
  
  <p>so now i can any pojo class to single method and get the response.This is just to avoid rewriting  the same code again and again.is this possible</p>
  
  <p><strong>Update</strong>
  To elaborate more:</p>
  
  <p>Suppose I need to make two requests. First one is to get userDetails and the other is patientDetails.So i have to create two model classes User and Patient.
  So in retrofit api i'll be having something like this</p>
  
  <pre><code>@POST
  Call&lt;User&gt; getDataFromServer(@Url String url, @Body HashMap&lt;String,Object&gt; hashMap);
  
  @POST
  Call&lt;Patient&gt; getDataFromServer(@Url String url, @Body HashMap&lt;String,Object&gt; hashMap);
  </code></pre>
  
  <p>and in my FragmentUser and FragmentPatient class i'll be doing this</p>
  
  <pre><code>  ApiCalls api = retrofit.create(ApiCalls.class);
  Call&lt;User&gt; call = api.getDataFromServer(StringConstants.URL,hashMap);
  call.enqueue(new Callback&lt;User&gt;() {
       //Response and failure callbacks
  }
  
  ApiCalls api = retrofit.create(ApiCalls.class);
  Call&lt;Patient&gt; call = api.getDataFromServer(StringConstants.URL,hashMap);
  call.enqueue(new Callback&lt;Patient&gt;() {
       //Response and failure callbacks
  }
  </code></pre>
  
  <p>but here the code is repaeting just beacuse of different pojo classes.I need to repeat the same code in every other fragments for different requests.
  So i need to make a generic method where it can accept any pojo class and then from fragment i'll be just passing the pojo to be mapped.</p>