title: Java Generics : Cannot convert from Object to T
body: <p>I have many response objects that I need to give to ui. I want to have a template so that I can do it, so far below code has not worked.</p>
  
  <pre><code>private &lt;T&gt; T getResult(Class clazz){
      String fileName = "/path/file.json";
      File file = new File(BaseEndpoint.class.getResource(fileName.getFile());
      T result = null;
  
      try {
          result = mapper.readValue(file, clazz);
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return result;
  }
  </code></pre>