title: Convert from JSon to multiple unknown java object types using GSon
body: <p>I have a netty decoder which uses GSon to convert JSon coming from web client to appropriate java objects.
  The requirement is:
  Client could be sending unrelated classes, Class A, Class B, Class C etc but I would like to use the <strong>same</strong> singleton decoder instance in the pipeline to do conversion(since I use spring for configuring it). The issue I am facing is I need to know the <code>class</code> object before hand.</p>
  
  <pre><code>public Object decode()
  {
      gson.fromJson(jsonString, A.class);
  }
  </code></pre>
  
  <p>This cannot decode B or C. The users of my library, now need to write separate decoders for each class instead of a cast later down the line. The only way I can see for doing this is to pass the String name of the class say "org.example.C" in the JSon string from web client, parse it out in the decoder and then use <code>Class.forName</code> to get the class. Is there a better way to do this?</p>