title: Gson TypeToken with dynamic ArrayList item type
body: <p>I have this code:</p>
  
  <pre><code>Type typeOfObjectsList = new TypeToken&lt;ArrayList&lt;myClass&gt;&gt;() {}.getType();
  List&lt;myClass&gt; objectsList = new Gson().fromJson(json, typeOfObjectsList);
  </code></pre>
  
  <p>It converts a JSON string to a <code>List</code> of objects.
  But now I want to have this <code>ArrayList</code> with a dynamic type (not just <code>myClass</code>), defined at runtime.</p>
  
  <p><strong>The <code>ArrayList</code>'s item type will be defined with <em>reflection</em>.</strong></p>
  
  <p>I tried this:</p>
  
  <pre><code>    private &lt;T&gt; Type setModelAndGetCorrespondingList2(Class&lt;T&gt; type) {
          Type typeOfObjectsListNew = new TypeToken&lt;ArrayList&lt;T&gt;&gt;() {}.getType();
          return typeOfObjectsListNew;
      }
  </code></pre>
  
  <p>But it doesn't work. This is the exception:</p>
  
  <pre><code>java.sql.SQLException: Fail to convert to internal representation: {....my json....}
  </code></pre>