title: How to get the Generic type for the Jackson ObjectMapper
body: <p>Java erases normally the <code>Generics</code> data on compilation, but there is a possibility to get that information (the Jackson <code>ObjectMapper</code> does that pretty well). </p>
  
  <p>My Problem: I have a Class with a property of List:</p>
  
  <pre><code>public class User {
      public List&lt;Long&gt; listProp;//it is public only to keep the example simple
  }
  </code></pre>
  
  <p>How can I get the correct <code>TypeReference</code> (or <code>JavaType</code> ?) so that I can map programatically a JSON String to the correct List Type, having the instance of the <code>Class</code> class (User.class) and the property name (listProp)? What I mean is this:</p>
  
  <pre><code>TypeReference typeReference = ...;//how to get the typeReference?
  List&lt;Long&gt; correctList = om.readValue(jsonEntry.getValue(), typeReference);//this should return a List&lt;Long&gt; and not eg. a List&lt;Integer&gt;
  </code></pre>