title: Converting Json into a DTO array
body: <p>I have an interesting JSON parsing problem, at least to me since I am doing this for the first time. I have the following sample JSON and I want to map it to equivalent DTOs:</p>
  
  <pre><code>{
      "modules":
      [
          {
              "name":"module1",
              "shortId":23425,
              "pmns":
              [
                  {
                      "name":"pmn1",
                      "position":1,
                      "pmnType":"D3"
                  },
                  {
                      "name":"pmn3",
                      "position":3,
                      "pmnType":"R2"
                  },
                  {
                      "name":"pmn7",
                      "position":5,
                      "pmnType":"S1"
                  },
              ]
          },
          {
              "name":"module2",
              "shortId":1572,
              "pmns":
              [
                  {
                      "name":"pmn1",
                      "position":3,
                      "pmnType":"D3"
                  },
                  {
                      "name":"pmn12",
                      "position":35,
                      "pmnType":"R2"
                  },
              ]
          }
      ]
  }
  </code></pre>
  
  <p>This is my ModuleDTO class:</p>
  
  <pre><code>public class ModuleDTO {
  
      private String _name;
      private short _shortId;
      private PmnDTO[] _pmns;
  
      public String getName() {
          return _name;
      }
  
      public short getShortId() {
          return _shortId;
      }
  
      public PmnDTO[] getPmns() {
          return _pmns;
      }
  
      @JsonProperty("name")
      public void setName(String name) {
          this._name = name;
      }
  
      @JsonProperty("shortId")
      public void setShortId(short shortId) {
          this._shortId = shortId;
      }
  
      @JsonProperty("pmns")
      public void setPmns(PmnDTO[] pmns) {
          this._pmns = pmns;
      }
  
  }
  </code></pre>
  
  <p>Not copied here but my PmnDTO class is similar, i.e. getters and setters for each property in the pmn object of JSON.</p>
  
  <p>I wrote the following code to try to map it to DTO. The library I am using is com.FasterXml.jackson (version 2.3.1)</p>
  
  <pre><code>// Got the response, construct a DTOs out of it ...
  ObjectMapper mapper = new ObjectMapper();
  StringReader reader = new StringReader(response); // Json Response
  
  // Convert the JSON response to appropriate DTO ...
  ModuleDTO moduleDto = mapper.readValue(reader, ModuleDTO.class);
  </code></pre>
  
  <p>Obviously, this code didn't work. Can someone tell, how can I map the JSON response to my DTOs, given that "modules" is an array in the JSON and it also contains a variable size array within itself.</p>
  
  <p>Thank You.</p>
  
  <p>(*Vipul)() ;</p>