title: Parsing JSON to Enum Fields
body: <p>in my Android application, I am returned a simple JSON object with simple key value pairs, eg:</p>
  
  <pre><code>{"username" : "billySmith", "gender" : 1}
  </code></pre>
  
  <p>And an enum with the respective field names <code>username</code> and <code>gender</code> (String and int, respectively). </p>
  
  <p>I am trying to use Gson to parse the JSON object and populate the enum fields with the json values.  I am a little uncertain of how to use GSON with enums.  I am familiar with the concept that an instance of an object should be set equal to <code>gson.fromJson(jsonObect, instanceType.class);</code>.  </p>
  
  <p>To add more detail, I am using Enums so that the values can be retrieved from anywhere in my android project.</p>
  
  <pre><code>if (response.getStatusLine().getStatusCode() == 200 &amp;&amp; result != "")
  {                               
      GlobalEnum globalEnum = GlobalEnum.getInstance();
      Gson gson = new GsonBuilder().create();
      globalEnum = gson.fromJson(result, GlobalEnum.class);
  }
  </code></pre>
  
  <p>where "result" is the string representation of an HTTP Response's entity</p>
  
  <p>GlobalEnum snippet:</p>
  
  <pre><code>public enum GlobalEnum
  {
      INSTANCE;
  
      private String username;
      private int gender;
  
      public static GlobalEnum getInstance()
      {
          return INSTANCE;
      }
  
      public int getGender()
      {
          return gender;
      }
  
      public void setGender(int gender)
      {
          this.gender = gender;
      }
  }
  </code></pre>
  
  <p>*Edit:
  Reworded: I have an enum, and I have a jsonObject.  Both the enum and JSON object have "username" and "gender".  using Gson, I would like to parse the JSON object so that the Values from the JSONobject will be assigned to the respective fields in the Enum.</p>