title: Java/jackson object mapping: how to convert a nested JSON array to a list of objects (might be best explain with an example)
body: <p>2 questions:</p>
  <ul>
  <li>how can I have a list of objects inside another list of objects? (in my example JSON, this would be list of Animal objects with a list of Specie objects inside it)</li>
  <li>how can I remove the static declaration in the inner class and have stuff still working ok?</li>
  </ul>
  <p>using the code below, I can have a list of Animal objects with a Specie array inside it.</p>
  <hr />
  <p>sample JSON:</p>
  <pre><code>[
      {&quot;name&quot;:&quot;Arthropod&quot;
          ,&quot;species&quot;:[
              {&quot;name&quot;:&quot;spider&quot;,&quot;class&quot;:&quot;Arachnida&quot;}
              ,{&quot;name&quot;:&quot;butterfly&quot;,&quot;class&quot;:&quot;Insecta&quot;}
              ]
      }
      ,{&quot;name&quot;:&quot;Mammal&quot;
          ,&quot;species&quot;:[
              {&quot;name&quot;:&quot;monkey&quot;,&quot;class&quot;:&quot;Primates&quot;}
              , {&quot;name&quot;:&quot;kangaroo&quot;,&quot;class&quot;:&quot;Diprotodontia&quot;}
          ]
      }
  ]
  </code></pre>
  <p>my code:</p>
  <pre><code>public class Animal
      private String name
      private Specie[] species;
      
      @JsonCreator
      public Animal(
          @JsonProperty(&quot;name&quot;) String name
          , @JsonProperty(&quot;specifies&quot;) Specie[] pets) {
          this.name = name;
          this.pets = pets;
      };
  
      static class Specie {
          private String name;
          private String class;
      }
      
  
  List&lt;Animal&gt; animals = new ObjectMapper().readValue(myJSON, new TypeReference&lt;List&lt;Animal&gt;&gt;(){});
  </code></pre>