title: Parse JSON to deeply nested generic with jackson
body: <p>I've been trying all kinds of solutions to get this working. But without success.</p>
  
  <p>I have a few classes like this</p>
  
  <pre><code>class Level1&lt;T&gt; {
  
      public Level2&lt;T&gt; l2;
  }
  
  class Level2&lt;T&gt; {
  
      public Level3&lt;T&gt; l3;
  }
  
  class Level3&lt;T&gt; {
  
      public List&lt;T&gt; objectsList;
  }
  </code></pre>
  
  <p><strong>T</strong> in this case <strong>can be any object</strong>, and should be possible to be <strong>resolved during runtime</strong>. </p>
  
  <p>My JSON looks like this:</p>
  
  <pre><code>{
      "Level1": {
          "Level2": {
              "Level3": {
                  "genericObject": [
                      { 
                        "attribute1": ..., 
                        "attribute2": ...
                      },
                      { 
                        "attribute1": ..., 
                        "attribute2": ...
                      } 
                  ]
              }
          }
      }
  }
  </code></pre>
  
  <p>The JSON property "genericObject" changes its name and attributes depending of which kind of object I'm receiving.</p>
  
  <p>I've tried defining in my ObjectMapper like this, in which I pass a Class object to my function (genericObjectClass):</p>
  
  <pre><code>JavaType javaType = TypeFactory.defaultInstance().constructParametricType(ArrayList.class, List.class, genericObjectClass);
  javaType = TypeFactory.defaultInstance().constructParametricType(Level3.class, javaType);
  javaType = TypeFactory.defaultInstance().constructParametricType(Level2.class, javaType);
  javaType = TypeFactory.defaultInstance().constructParametricType(Level1.class, javaType);
  
  Level1&lt;genericObject&gt; l1 = objectMapper.readValue(jsonString, javaType);
  </code></pre>
  
  <p>Tried solutions:</p>
  
  <p><a href="https://stackoverflow.com/questions/24143440/deserialising-nested-generics-in-jackson">(de)serialising Nested Generics in Jackson</a></p>
  
  <p><a href="https://stackoverflow.com/questions/21810356/how-to-use-jackson-with-generics">How to use Jackson with Generics</a></p>
  
  <p><a href="https://stackoverflow.com/questions/17400850/is-jackson-really-unable-to-deserialize-json-into-a-generic-type">Is Jackson really unable to deserialize json into a generic type?</a></p>