title: How to (completely) deserialize json into a generic List?
body: <p>When using an <code>ObjectMapper</code> to transform a json <code>String</code> into an entity, I can make it generic as:</p>
  
  <pre><code>public &lt;E&gt; E getConvertedAs(String body, Class&lt;E&gt; type) throws IOException {
      return mapper.readValue(body, type);
  }
  </code></pre>
  
  <p>Now let's say I want to read collections. I can do:</p>
  
  <pre><code>List&lt;SomeEntity&gt; someEntityList = asList(mapper.readValue(body, SomeEntity[].class));
  List&lt;SomeOtherEntity&gt; someOtherEntityList = asList(mapper.readValue(body, SomeOtherEntity[].class));
  </code></pre>
  
  <p>I would like to write an equivalent method of the above, but for collections. Since you can't have generic arrays in java, something like this won't work:</p>
  
  <pre><code>public &lt;E&gt; List&lt;E&gt; getConvertedListAs(String body, Class&lt;E&gt; type) {
      return mapper.readValue(body, type[].class);
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/a/20398614/5961990">Here</a> there is a solution that almost works:</p>
  
  <pre><code>mapper.readValue(jsonString, new TypeReference&lt;List&lt;EntryType&gt;&gt;() {});
  </code></pre>
  
  <p>The problem is that it doesn't deserialize into a list of <code>E</code>, but of <code>LinkedHashMap.Entry</code>. Is there any way of going going a step further, something like the following?</p>
  
  <pre><code>public &lt;E&gt; List&lt;E&gt; getConvertedListAs(String body, Class&lt;E&gt; type) {
      mapper.readValue(body, new TypeReference&lt;List&lt;type&gt;&gt;() {}); // Doesn't compile
  }
  </code></pre>