title: Gson.toJson() and inheriting from a generic class
body: <p>I have the following class:</p>
  
  <pre><code>public static class TestSomething {
  
      Integer test;
  
      public TestSomething(Integer test) {
          this.test = test;
      }
  
      // getter and setter for test
  }
  </code></pre>
  
  <p>Ok, now create a collection of this class and serialize it with Gson:</p>
  
  <pre><code>Collection&lt;TestSomething&gt; tests = Arrays.asList(
      new TestSomething(1), 
      new TestSomething(2), 
      new TestSomething(3)
  );
  String json = new Gson().toJson(tests, new TypeToken&lt;Collection&lt;TestSomething&gt;&gt;() {}.getType());
  </code></pre>
  
  <p>After this, the String <code>json</code> is set to</p>
  
  <pre><code>[{"test":1},{"test":2},{"test":3}]
  </code></pre>
  
  <p>Which is great.</p>
  
  <p>But now, all of my model classes inherit from a generic type <code>Identifiable&lt;T&gt;</code> which provides just two methods <code>T getId()</code> and <code>void setId(T)</code>. So I change the <code>TestSomething</code>-class from above to</p>
  
  <pre><code>public static class TestSomething extends Identifiable&lt;Long&gt; {
      // same as above
  }
  </code></pre>
  
  <p>When I try to put this through <code>Gson.toJson()</code>, Gson ends up with the following Exception:</p>
  
  <pre><code>java.lang.UnsupportedOperationException: Expecting parameterized type, got class path.to.TestSomething.
   Are you missing the use of TypeToken idiom?
   See http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener
          at com.google.gson.TypeInfoFactory.getActualType(TypeInfoFactory.java:97)
          ...
  </code></pre>
  
  <p>So, what do I have to do to get this work?</p>