title: How do I use custom deserialization on gson for generic type?
body: <p>For standard POJO, we can use the following</p>
  
  <pre class="lang-java prettyprint-override"><code>GsonBuilder gson = new GsonBuilder();
  gson.registerTypeAdapter(MyType2.class, new MyTypeAdapter());
  gson.registerTypeAdapter(MyType.class, new MySerializer());
  gson.registerTypeAdapter(MyType.class, new MyDeserializer());
  gson.registerTypeAdapter(MyType.class, new MyInstanceCreator());
  </code></pre>
  
  
  
  <p>How about if the POJO is generic? The <a href="https://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserialization" rel="nofollow noreferrer">Gson user guide</a> doesn't mention it. Below is my code but it's not the correct one.</p>
  
  <pre class="lang-java prettyprint-override"><code>gsonBuilder.registerTypeAdapter(CustomResponse&lt;POJOA&gt;.getClass(), new POJOADeserializer());
              gsonBuilder.registerTypeAdapter(CustomResponse&lt;POJOB&gt;.getClass(), new POJOBDeserializer());
              gsonBuilder.registerTypeAdapter(CustomResponse&lt;POJOC&gt;.getClass(), new POJOCDeserializer());
  </code></pre>