title: How to handle deserializing with polymorphism?
body: <p>I have a class like:</p>
  
  <pre><code>public class Barn {
      String type;
      Animal animal;
  }
  
  public class Horse extends Animal {
  }
  
  public class Cow extends Animal {
  }
  </code></pre>
  
  <p>and I want to serialize a list of them:</p>
  
  <pre><code>List&lt;Barn&gt; barns = new ArrayList&lt;Barn&gt;();
  
  Barn barn1 = new Barn();
  barn1.setType("horse");
  barn1.setAnimal(new Horse());
  barns.add(barn1);
  
  Barn barn2 = new Barn();
  barn2.setType("cow");
  barn2.setAnimal(new Cow());
  barns.add(barn2);
  
  ...
  
  Group&lt;Barn&gt; barns = gson.fromJson(serialized);   
  </code></pre>
  
  <p>When I serialize, type information will be lost for the Animal attribute. Is there a way I could install a parser listener somehow so that I could provide the right class to deserialize as when each element in the list is encountered? That was the idea behind manually supplying a string describing the class type.</p>
  
  <p>Thanks</p>