title: Deserialization of generic collections with Gson
body: <p>I have some difficulties with json deserialization using GSon and I hope somebody can help me.</p>
  
  <p>I want to deserialize the following json snippet:</p>
  
  <pre><code>{
      "fieldA": "valueA",
      "myCollection": {
          "AnotherClass": [
              {
                  "objectAfieldA": "valueB",
                  "objectAfieldB": "valueC"
              },
              {
                  "objectAfieldA": "valueD",
                  "objectAfieldB": "valueE"
              }
          ]
      }
  }
  </code></pre>
  
  <p>the corresponding overall class has following fields:</p>
  
  <pre><code>...
  String fieldA;
  List&lt;AnotherClass&gt; = new ArrayList&lt;AnotherClass&gt;();
  ....
  </code></pre>
  
  <p>Now, my problem is that when I deserialize, using <code>fromJson(jsonSample, resultContainer.class)</code>, without the <code>List&lt;T&gt;</code> element, everything is good, but I get a <code>NullPointerException</code> when I include the contained list. I've read about how to deal with collections of generic types and the use of <code>TypeToken</code>, but I can't apply this knowledge when my collection is part of another class… </p>
  
  <p>I really would appreciate any help to solve this.</p>