title: How to use Gson to deserialize a Json with polymorphic sub object
body: <p>I have problem when I design a Class to serialize and deserialize.</p>
  
  <p>Here is the problem, I have a Class</p>
  
  <pre><code>class Thing {
    int a;
    String b;
    String type;
    Type typeinfo;
  }
  </code></pre>
  
  <p>Basically the <code>Type</code> is the an abstract class like</p>
  
  <pre><code>abstract class Type {
   //nothing here
  }
  </code></pre>
  
  <p>and I have a few implementation</p>
  
  <pre><code>class CarType extends Type {
    int x;
    int y;
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>class TruckType extends Type {
    list&lt;Integer&gt; listOfInt;
  }
  </code></pre>
  
  <p>The <code>String type</code> is set to <code>"CarType"</code> or <code>"TruckType"</code> even others and I could know what's actual type of <code>typeinfo</code> </p>
  
  <p>It's good to use Gson to serialize it but how to deserialize the json string? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is an example of Json String</p>
  
  <pre><code>case1:
  {
   "a" : 1,
   "b" : "aaa",
   "type": "car",
   "typeinfo": {
      "x" : 10,
      "y" : 100
    }
  }
  
  case2: 
  { 
    "a" : 1,
    "b" : "aaa",
   "type": "truck",
   "typeinfo": {
     "listOfInt" : [1, 2, 3]
   }
  }
  </code></pre>
  
  <p>Just a quick mock up but I guess the idea should be clear, and the problem is I don't want to put the "type" into the typeinfo which supposed only the information.</p>