title: Gson - deserialization to specific object type based on field value
body: <p>I want to deserialize json objects to specific types of objects (using Gson library) based on <code>type</code> field value, eg.:</p>
  
  <pre><code>[
      {
            "type": "type1",
            "id": "131481204101",
            "url": "http://something.com",
            "name": "BLAH BLAH",
            "icon": "SOME_STRING",
            "price": "FREE",
            "backgroundUrl": "SOME_STRING"
      },
      {
          ....
      }
  ]
  </code></pre>
  
  <p>So <code>type</code> field will have different (but known) values. Based on that value I need to deserialize that json object to appropriate model object, eg.: Type1Model, Type2Model etc. 
  I know I can easily do that before deserialization by converting it to <code>JSONArray</code>, iterate through it and resolve which type it should be deserialized to. But I think it's ugly approach and I'm looking for better way. Any suggestions?</p>