title: com.google.gson.internal.LinkedTreeMap cannot be cast to my class
body: <p>I have some problems with getting my object from a JSON string. </p>
  
  <p>I got the class <code>Product</code></p>
  
  <pre><code>public class Product {
      private String mBarcode;
      private String mName;
      private String mPrice;
  
      public Product(String barcode, String name, String price) {
          mBarcode = barcode;
          mName = name;
          mPrice = price;
      }
  
      public int getBarcode() {
          return Integer.parseInt(mBarcode);
      }
  
      public String getName() {
          return mName;
      }
  
      public double getPrice() {
          return Double.parseDouble(mPrice);
      }
  }    
  </code></pre>
  
  <p>From my server I get an <code>ArrayList&lt;Product&gt;</code> in JSON String representation. For example:</p>
  
  <pre><code>[{"mBarcode":"123","mName":"Apfel","mPrice":"2.7"},
  {"mBarcode":"456","mName":"Pfirsich","mPrice":"1.1111"},
  {"mBarcode":"89325982","mName":"Birne","mPrice":"1.5555"}] 
  </code></pre>
  
  <p>This String is generated like this:</p>
  
  <pre><code>public static &lt;T&gt; String arrayToString(ArrayList&lt;T&gt; list) {
      Gson g = new Gson();
      return g.toJson(list);
  }
  </code></pre>
  
  <p>To get my Object back I use this function:</p>
  
  <pre><code>public static &lt;T&gt; ArrayList&lt;T&gt; stringToArray(String s) {
      Gson g = new Gson();
      Type listType = new TypeToken&lt;ArrayList&lt;T&gt;&gt;(){}.getType();
      ArrayList&lt;T&gt; list = g.fromJson(s, listType);
      return list;
  }
  </code></pre>
  
  <p>But when calling </p>
  
  <pre><code>String name = Util.stringToArray(message).get(i).getName();
  </code></pre>
  
  <p>I get the error 
  <em>com.google.gson.internal.LinkedTreeMap cannot be cast to object.Product</em></p>
  
  <p>What am I doing wrong? It looks like it created a List of LinkedTreeMaps but how do i convert those into my Product Object?</p>