title: How to make a generic function for Jackson/ObjectMapper in java?
body: <p>So I have these methods:</p>
  <pre><code>private List&lt;ClientRepresentation&gt; toClientRepresentation(String json) {
      try {
          return objectMapper.readValue(json, new TypeReference&lt;List&lt;ClientRepresentation&gt;&gt;() {
          });
      } catch (JsonProcessingException e) {
          throw new RuntimeException(&quot;Could not parse json.&quot;);
      }
  }
  
  private List&lt;RoleRepresentation&gt; toRoleRepresentation(String json) {
      try {
          return objectMapper.readValue(json, new TypeReference&lt;List&lt;RoleRepresentation&gt;&gt;() {
          });
      } catch (JsonProcessingException e) {
          throw new RuntimeException(&quot;Could not parse json.&quot;);
      }
  }
  
  private List&lt;UserRepresentation&gt; toUserRepresentation(String json) {
      try {
          return objectMapper.readValue(userJson, new TypeReference&lt;List&lt;UserRepresentation&gt;&gt;() {
          });
      } catch (JsonProcessingException e) {
          throw new RuntimeException(&quot;Could not parse json.&quot;);
      }
  }
  </code></pre>
  <p>You can see these are similar... Would like to have one method for these... Something like this:</p>
  <pre><code>private List&lt;T&gt; toObjectsList(String json, Class classToConvert) {
      try {
          return objectMapper.readValue(json, new TypeReference&lt;List&lt;classToConvert&gt;&gt;() {
          });
      } catch (JsonProcessingException e) {
          throw new RuntimeException(&quot;Could not parse json.&quot;);
      }
  }
  </code></pre>
  <p>Is it possible? How?</p>
  <p>Thanks in advance.</p>