title: How to handle Dynamic JSON in Retrofit?
body: <p>I am using the retrofit efficient networking library, but I am unable to handle Dynamic JSON which contains single prefix  <code>responseMessage</code> which changes to <code>object</code> randomly, the same prefix ( <code>responseMessage</code>) changes to String in some cases (dynamically). </p>
  
  <p>Json format Object of responseMessage:</p>
  
  <pre><code>{
     "applicationType":"1",
     "responseMessage":{
        "surname":"Jhon",
        "forename":" taylor",
        "dob":"17081990",
        "refNo":"3394909238490F",
        "result":"Received"
     }
  
  }
  </code></pre>
  
  <p><code>responseMessage</code>  Json format dynamically changes to type string:</p>
  
  <pre><code> {
         "applicationType":"4",
         "responseMessage":"Success"          
   }
  </code></pre>
  
  <p>My problem is since retrofit has built-in <code>JSON</code> parsing, I have to assign single POJO per request! but the REST-API unfortunately, is built on dynamic <code>JSON</code> responses. The prefix will change from string to object randomly in both <strong>success(...)</strong> and <strong>failure(...)</strong> methods!  </p>
  
  <pre><code>void doTrackRef(Map&lt;String, String&gt; paramsref2) {
      RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://192.168.100.44/RestDemo").build();
  
  
  
      TrackerRefRequest userref = restAdapter.create(TrackerRefRequest.class);
      userref.login(paramsref2,
              new Callback&lt;TrackerRefResponse&gt;() {
                  @Override
                  public void success(
                          TrackerRefResponse trackdetailresponse,
                          Response response) {
  
                      Toast.makeText(TrackerActivity.this, "Success",
                      Toast.LENGTH_SHORT).show();
  
                  }
  
                  @Override
                  public void failure(RetrofitError retrofitError) {
  
  
                      Toast.makeText(TrackerActivity.this, "No internet",
                          Toast.LENGTH_SHORT).show();
                  }
  
  
              });
  }
  </code></pre>
  
  <p>Pojo:</p>
  
  <pre><code>public class TrackerRefResponse {
  
  
  private String applicationType;
  
      private String responseMessage;          //String type
  
  //private ResponseMessage responseMessage;  //Object of type ResponseMessage
  
  //Setters and Getters
  
  
  }
  </code></pre>
  
  <p>In above code POJO TrackerRefResponse.java  prefix responseMessage is set to string or object of type responseMessage , so we can create the POJO with ref variable with same name (java basics :)   ) so I'm looking for same solution for dynamic <code>JSON</code> in Retrofit.
  I know this is very easy job in normal http clients with async task, but it's not the best practice in the REST-Api <code>JSON</code> parsing! looking at the performance <a href="https://stackoverflow.com/questions/16902716/comparison-of-android-networking-libraries-okhttp-retrofit-volley/18863395#18863395"><strong>Benchmarks</strong></a> always Volley or Retrofit is the best choice, but I'm failed handle dynamic <code>JSON</code>!  </p>
  
  <p>Possible solution I Know </p>
  
  <ol>
  <li><p>Use old asyc task with http client parsing. :( </p></li>
  <li><p>Try to convince the RESTapi backend developer.</p></li>
  <li><p>Create custom Retrofit client :)</p></li>
  </ol>