title: JSON deserialization using GSON skips data members from a hashmap within a hashmap
body: <p>I'm using GSON to deserialize some JSON files.  Here's the deserialization method I've written, I read the JSON file and store the whole thing as a string which I pass to this method.  This method works successfully for 4 out of the 5 JSON files related to this project.</p>
  
  <pre><code>protected ArrayList&lt;Entry&gt; deserialize(String json) throws Exception
  {
      ArrayList&lt;Entry&gt; list = new ArrayList&lt;Entry&gt;( );
  
  
      JsonParser parser = new JsonParser();
  
      JsonArray jarray = (JsonArray) parser.parse(json);
  
      for (int i = 0; i &lt; jarray.size(); i++)
      {
  
          // Parse out the brand
          JsonObject jentry = (JsonObject) jarray.get(i);
  
          JsonPrimitive jbrand = jentry.getAsJsonPrimitive("brand");
  
          String className = jbrand.getAsString();
  
          Entry entry = (Entry) gson.fromJson(jentry, Class.forName(className));
  
          list.add(entry);
      }
  
      return list;
  }
  </code></pre>
  
  <p>Here's the JSON file that I parsed and put in the string, there's several objects that get bound to 'jentry' but I'll just include one.  If it looks weird it's probably because I've been using a firefox plugin to view the JSON files and I copy/pasted from that plugin.</p>
  
  <pre><code>[
  
  *
    -
    {
        o pattern: "3 5 * * 1-5"
        o starts: 1288249260913
        o ends: 1291125660913
        o skipHolidays: false
        o lastFired: 1289988180395
        o
          -
          template: {
              + location: ""
              + damageCause: ""
              + signed: false
              + signedBy: ""
              + approvedBy: "Ralph"
              + requestedBy: "Ralph"
              + estHours: 0
              + actHours: 0
              + chargeTo: ""
              + priority: "ROUTINE"
              + reason: ""
              + materials: ""
              + serviceId: 1
              + descr: "HELP WITH LEAVES,BLOW LEAVES IN YOUR AREA NEAR DRAINS Check for garbage. [sp] Mow and weedeat where needed in your area. [sp] Work on leaves where needed. [wi]"
              + comments: [ ]
              + futureId: 3
              + inventoryId: -1
              +
                -
                trail: [
                    #
                      -
                      {
                          * stamp: 1288026816857
                          * status: "OPEN"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288026889374
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288194095170
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288287964481
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288785076532
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288797119525
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289307416921
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289308339165
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289834523635
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289847660913
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                ]
              + requestDate: 1289329260913
              + assignedDate: 1288029660912
              + supplies: [ ]
              + id: 3
              + updateDate: 1289847660913
              + createUserId: 2
              + updateUserId: 2
              + createDate: 1288026816857
              + brand: "org.workplicity.marist.grounds.GroundsRequest"
          }
        o workSlateId: 16
        o serviceId: 1
        o enabled: false
        o id: 3
        o updateDate: 1291235385719
        o createUserId: 2
        o updateUserId: 2
        o createDate: 1288026889373
        o brand: "org.workplicity.entry.event.Weekdays"
    }
  </code></pre>
  
  <p>The problem is that when the GSON gets turned back into JSON (serialization?) it's missing some fields.  Here's the output, the relevant missing lines are everything below 'template:' and above 'serviceID:', I'll go ahead and include the whole object again.</p>
  
  <pre><code>[
  
  *
    -
    {
        o pattern: "3 5 * * 1-5"
        o starts: 1288249260913
        o ends: 1291125660913
        o skipHolidays: false
        o lastFired: 1289988180395
        o
          -
          template: {
              + serviceId: 1
              + descr: "HELP WITH LEAVES,BLOW LEAVES IN YOUR AREA NEAR DRAINS Check for garbage. [sp] Mow and weedeat where needed in your area. [sp] Work on leaves where needed. [wi]"
              + comments: [ ]
              + futureId: 3
              + inventoryId: -1
              +
                -
                trail: [
                    #
                      -
                      {
                          * stamp: 1288026816857
                          * status: "OPEN"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288026889374
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288194095170
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288287964481
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288785076532
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1288797119525
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289307416921
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289308339165
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289834523635
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                    #
                      -
                      {
                          * stamp: 1289847660913
                          * status: "DISPATCHED"
                          * byId: 2
                      }
                ]
              + requestDate: 1289329260913
              + assignedDate: 1288029660912
              + supplies: [ ]
              + id: 3
              + updateDate: 1289847660913
              + createUserId: 2
              + updateUserId: 2
              + createDate: 1288026816857
              + brand: "org.workplicity.marist.grounds.GroundsRequest"
          }
        o workSlateId: 16
        o serviceId: 1
        o enabled: false
        o id: 3
        o updateDate: 1299694066807
        o createUserId: 2
        o updateUserId: 2
        o createDate: 1288026889373
        o brand: "org.workplicity.entry.event.Weekdays"
    }
  </code></pre>
  
  <p>This happens for every object in the JSON file.  Debugging in NetBeans has revealed that the JsonObject 'jentry' has a hashtable with corresponding key value pairs for each data member in the JSON string; and the 'template' is stored as a hashtable within this hashtable which may or may not be a problem I honestly haven't been able to find out.</p>
  
  <p>Now when I initially ran this method on the problem JSON file I got an exception at this line:</p>
  
  <pre><code>Entry entry = (Entry) gson.fromJson(jentry, Class.forName(className));
  </code></pre>
  
  <p>The problem was that the particular classes involved with this specific JSON file didn't have no-args constructors so I had to register some InstanceCreators to the GSON builder like so:</p>
  
  <pre><code>gsonBuilder.registerTypeAdapter(Weekdays.class, new WeekdaysInstanceCreator());
  gsonBuilder.registerTypeAdapter(Once.class, new OnceInstanceCreator());
  </code></pre>
  
  <p>After I did that the exception stopped being thrown and everything appears to have worked, minus the missing fields of course.  </p>
  
  <p>So that's where I am, I'm really at a loss as to what's going wrong.  Any help at all is greatly appreciated.</p>