title: Strange behavior when deserializing nested, generic classes with GSON
body: <p>I'm writing a class which will connect to a server and based on some arguments, retrieve a json-string which will be parsed with GSON to the specified (via generics) class. </p>
  
  <p>A stripped down version of the class in charge looks like this:</p>
  
  <pre><code>class Executor&lt;T&gt; {
  
      private Response&lt;T&gt; response;
  
      public void execute() {
          Type responseType = new TypeToken&lt;Response&lt;T&gt;&gt;() {}.getType();
          this.response = new Gson().fromJson(json, responseType);
      }
  
      public Response&lt;T&gt; getResponse() { return this.response; }
  
  }
  </code></pre>
  
  <p>(the <code>JSON</code>-variable <a href="http://pastebin.com/hgp1prri">looks like this</a>.)</p>
  
  <p>The class which stores the data once de-serialized looks like this:</p>
  
  <pre><code>class Response&lt;T&gt; {
  
      private List&lt;T&gt; data = null;
  
      public List&lt;T&gt; getData() { return this.data; }
  
  }
  </code></pre>
  
  <p>The class which the data is trying to be de-serialized to:</p>
  
  <pre><code>public class Language {
      public String alias;
      public String label;
  }
  </code></pre>
  
  <p>And the code which runs utilizes the classes above:</p>
  
  <pre><code>Executor&lt;Language&gt; executor = new Executor&lt;Language();
  List&lt;Language&gt; languages = executor.execute().getResponse().getData();
  System.out.println(languages.get(0).alias); // exception occurs here
  </code></pre>
  
  <p>Which results in the following exception</p>
  
  <blockquote>
    <p>ClassCastException: com.google.gson.internal.StringMap cannot be cast to sunnerberg.skolbibliotek.book.Language</p>
  </blockquote>
  
  <p>Any help or suggestions are greatly appreciated!</p>