title: With Gson and Retrofit2 Is there a way to write a "generic" TypeConverter to retrieve the payload from an envelope?
body: <p>I have this responsebody</p>
  <pre><code>{
    &quot;status&quot;:&quot;OK&quot;,
    &quot;payload&quot;:{}
  }
  </code></pre>
  <p>where payload is generic (a java-representation would look like <a href="https://gist.github.com/SennaGehenna/3eede2b9a54d27bd2764e11365b4523b" rel="nofollow noreferrer">this</a>)</p>
  <p>There was the <a href="https://gist.github.com/SennaGehenna/29ee84947c861e426607f65b3f8f7033" rel="nofollow noreferrer">converter</a> stuff for Retrofit1, but Retrofit2 doesn't seem to allow you to do that generically, only type-specific, which is not an option, when you have 70+ different response-bodies.</p>
  <hr />
  <p>Edit:</p>
  <p>Since there seems to be confusion here, I'm not looking to convert json-strings into objects.</p>
  <p>When I get the aforementioned ResponseBody, I want to be able to write the following in my Retrofit-interface</p>
  <pre><code>@POST(&quot;someAddress&quot;)
  SomeResponse getData();
  </code></pre>
  <p>instead of</p>
  <pre><code>@POST(&quot;someAddress&quot;)
  ResponseWrapper&lt;SomeResponse&gt; getData();
  </code></pre>
  <p>There are TypeAdapters for Gson that can do that for definitive types (as in &quot;I have a class <code>Animal</code> and need GSON to deserialize it correctly to <code>Dog</code>, <code>Cat</code> and <code>Orangutan</code>), but NOT for generic types (which is what I would need with my generic payload.</p>
  <p>I could register a typeadapter for every possible payload, but that's plain madness, I have over 70 different payload-objects</p>