title: Get nested JSON object with GSON : Deserialization
body: <p>I have gone through the threads from SOF which talks about getting nested JSON using GSON. <a href="https://stackoverflow.com/questions/23070298/get-nested-json-object-with-gson-using-retrofit">Link 1</a> <a href="https://stackoverflow.com/questions/27805810/parsing-nested-json-objects-with-gson">Link 2</a>. My JSON file is as shown below</p>
  
  <pre><code>{
     "Employee_1": {
        "ZipCode": 560072,
        "Age": 50,
        "Place": "Hawaii",
        "isDeveloper": true,
        "Name": "Mary"
     },
     "Employee_2": {
        "ZipCode": 560072,
        "Age": 80,
        "Place": "Texas",
        "isDeveloper": true,
        "Name": "Jon"
     }
  }
  </code></pre>
  
  <p>my classes are as shown below</p>
  
  <pre><code>public class Staff {
  
      String Employee_1 ; 
  }
  
  class addnlInfo{
      String Name;
      String Place;
      int Age;
      int Zipcode;
      boolean isDeveloper;
  }  
  </code></pre>
  
  <p>The deserializer class which I built is as shown below</p>
  
  <pre><code>class MyDeserializer implements JsonDeserializer&lt;addnlInfo&gt;{
  
      public addnlInfo deserialize1(JsonElement je, Type type, JsonDeserializationContext jdc)
          throws JsonParseException
      {
          // Get the "content" element from the parsed JSON
          JsonElement content = je.getAsJsonObject().get("Employee_1");
  
          // Deserialize it. You use a new instance of Gson to avoid infinite recursion
          // to this deserializer
          return new Gson().fromJson(content, addnlInfo.class);
  
      }
  
      @Override
      public TokenMetaInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
              throws JsonParseException {
          // TODO Auto-generated method stub
          return null;
      }
  </code></pre>
  
  <p>The main file </p>
  
  <pre><code>Gson gson = new GsonBuilder()
                  .registerTypeAdapter(addnlInfo.class, new MyDeserializer())
                  .create();
  
  String jsonObject=  gson.toJson(parserJSON);
  addnlInfo info= gson.fromJson(jsonObject, addnlInfo .class);
  System.out.println(info.Age + "\n" + info.isDeveloper + "\n" + info.Name + "\n" + info.Place);
  
  
  Staff parentNode = gson.fromJson(jsonObject, Staff.class);
  System.out.println(parentNode.Employee_1);
  </code></pre>
  
  <p>The problem: </p>
  
  <p>My Subparent element (e.g. 'Employee_1') keeps changing. Do I have to construct multiple deserializers?</p>
  
  <p>Also, I get "Expected a string but was BEGIN_OBJECT" which I understand as we use nestedJSON.</p>