title: How to deserialize an array of objects using Jackson or any other api?
body: <p>I have a model defined to which i need to map the jsonArray.The model is as follows:</p>
  
  <pre><code>@JsonPropertyOrder({
      "Command",
      "Created",
      "Id",
      "Image",
      "Labels",
      "Names",
      "Ports",
      "Status"
  })
  public class Container {
  
      @JsonProperty("Command")
      private String Command;
  
      @JsonProperty("Created")
      private long Created;
  
      @JsonProperty("Id")
      private String Id;
  
      @JsonProperty("Image")
      private String Image;
  
      @JsonProperty("Labels")
      private List&lt;String&gt; Labels;
  
      @JsonProperty("Names")
      private List&lt;String&gt; Names = new ArrayList&lt;String&gt;();
  
      @JsonProperty("Ports")
      private List&lt;Port&gt; Ports = new ArrayList&lt;Port&gt;();
  
      @JsonProperty("Status")
      private String Status;
  
      //Getters and Setters
  }
  </code></pre>
  
  <p>The response is JSONArray and this is what i have to map to the Container Class which is as follows:</p>
  
  <pre><code>[  
    {  
      "Command":"/usr/sbin/sshd -D",
      "Created":1429686533,
      "Id":"c00afc1ae5787282fd92b3dde748d203a83308d18aaa566741bef7624798af10",
      "Image":"jay8798:latest",
      "Labels":{  
  
      },
      "Names":[  
        "/jay8798"
      ],
      "Ports":[  
        {  
          "IP":"0.0.0.0",
          "PrivatePort":22,
          "PublicPort":32845,
          "Type":"tcp"
        },
        {  
          "IP":"0.0.0.0",
          "PrivatePort":3306,
          "PublicPort":32846,
          "Type":"tcp"
        }
      ],
      "Status":"Up 12 hours"
    },
    {  
      "Command":"/usr/sbin/sshd -D",
      "Created":1429686039,
      "Id":"d70f439231d99889c1a8e96148f13a77cb9b83ecf8c9d4c691ddefa40286c04c",
      "Image":"jay898:latest",
      "Labels":{  
  
      },
      "Names":[  
        "/jay898"
      ],
      "Ports":[  
        {  
          "IP":"0.0.0.0",
          "PrivatePort":22,
          "PublicPort":32841,
          "Type":"tcp"
        },
        {  
          "IP":"0.0.0.0",
          "PrivatePort":3306,
          "PublicPort":32842,
          "Type":"tcp"
        }
      ],
      "Status":"Up 12 hours"
    }
  ]
  </code></pre>
  
  <p>This is what I have tried but nothing seems to be working:</p>
  
  <pre><code>Container[] containerList = mapper.readValue(containerResponse, Container[].class);
  int totalContainers = containerList.length;
  
  //This will return correct length of the container.
  System.out.println("This is the retrived size : " + containerList.length); 
  
  for(Container cont : containerList) {
      // this statement will print 'null'.There is no exception thrown at this point.
      System.out.println("Container Id : "+cont.getId());
  }
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>List&lt;Container&gt; containerList = 
            mapper.readValue(containerResponse, new TypeReference&lt;List&lt;MyClass&gt;&gt;(){});
  </code></pre>
  
  <p>I followed <a href="https://stackoverflow.com/questions/6349421/how-to-use-jackson-to-deserialise-an-array-of-objects">Jackson Deserialize</a> and tried all the solutions mentioned in the post.
  It is not able to map to the model.All the fields are null one it reads the values. No value is mapped to the attribute of Container class.Any thing missing in the model or do i need to write a customer logic to deserialize the json ?</p>