title: Use GSON to map changing field name to POJO
body: <p>I am writing an <code>Android</code> app, and using <code>RetroFit</code> to communicate with the REST API. I have all the classes/POJO's written, except one.</p>
  
  <p>Here is the Java for the specific class.
  This is the parent class, which is the root of the problem. I need to be able to map the <code>userNameResponse</code> variable to the users name in the <code>JSON</code> below</p>
  
  <pre><code>public class DiTopicStats {
  
      private UserNameResponse userNameResponse;
  
      public UserNameResponse getUserNameResponse() {
          return userNameResponse;
      }
  
      public void setUserNameResponse(UserNameResponse userNameResponse) {
          this.userNameResponse = userNameResponse;
      }
  }
  </code></pre>
  
  <p>and the child class, which should be fine as long as I can map to it from the above parent class:</p>
  
  <pre><code>public class UserNameResponse {
  
      //Fields
      //Getters and Setters
  }
  </code></pre>
  
  <p>The JSON that is returned contains a field which changes per response. The field is the users name. For example:</p>
  
  <pre><code>{
      "sMessage": "",
      "diStatus": {
          "diTopicWrongAns": {
              //Some fields
          },
          "diOverallStats": {
              //Some more fields
          },
          "diUserStats": {
              "John Smith": { //PROBLEM: This name changes
                  //some other fields
              }
          }
      }
  }
  </code></pre>
  
  <p>So in this case, the name "John Smith" has a dynamic field name. Realistically, it could be any string with letters, numbers, a <code>-</code> or a <code>.</code> in it.</p>
  
  <p>My question is, using RetroFit, how can I create a Java class that lets RetroFit map a field to a variable?</p>
  
  <p>I'm aware you can specify a <code>SerialisedName</code> but can this be done programatically at runtime, because I will have the <code>name</code> or the user at this stage.</p>
  
  <p>Thanks.</p>