title: Creating POJOs to match a JSON structure
body: <p>I have devised a JSON structure to represent a table with header columns plus table rows that looks like the following.</p>
  
  <pre><code>{
    "header": [
      {
        "fieldType": "STRING",
        "readOnly": true,
        "headerValue": "name"
      },
      {
        "fieldType": "STRING",
        "readOnly": true,
        "headerValue": "description"
      }
    ],
    "rows": [
      [
        {
          "fieldValue" : "engine"            
        },
        {
          "fieldValue" : "this is an engine"
        }
      ],
      [
        {
          "fieldValue" : "engine"            
        },
        {
          "fieldValue" : "this is an engine"
        }
      ],
      [
        {
          "fieldValue" : "engine"            
        },
        {
          "fieldValue" : "this is an engine"
        }
      ],
      [
        {
          "fieldValue" : "engine"            
        },
        {
          "fieldValue" : "this is an engine"
        }
      ]
    ]
  }
  </code></pre>
  
  <p>A row is for example</p>
  
  <pre><code>[
    {
      "fieldValue" : "engine"            
    },
    {
      "fieldValue" : "this is an engine"
    }
  ]
  </code></pre>
  
  <p>The number of entries in a row matches the number of header columns. So <code>"engine"</code> is the <code>"name"</code> column and <code>"this is an engine"</code> is the <code>"description"</code> column</p>
  
  <p>When I use GSON to turn my POJO's into a JSON String the closest I have got to match this structure is:</p>
  
  <pre><code>{
    "header": [
      {
        "fieldType": "STRING",
        "readOnly": true,
        "headerValue": "name"
      },
      {
        "fieldType": "STRING",
        "readOnly": true,
        "headerValue": "description"
      }
    ],
    "rows": [
      {
        "fieldValues": [
          "engine",
          "this is an engine"
        ]
      },
      {
        "fieldValues": [
          "engine",
          "this is an engine"
        ]
      },
      {
        "fieldValues": [
          "engine",
          "this is an engine"
        ]
      },
      {
        "fieldValues": [
          "engine",
          "this is an engine"
        ]
      }
    ]
  }
  </code></pre>
  
  <p>Here's the code I'm using to test</p>
  
  <pre><code>enum FieldType {
  
      STRING,
      BOOLEAN,
      NUMBER,
      PHOTO,
      PHOTOLIST;
  
  }
  
  class SurveyFields {
  
      private List&lt;SurveyColumn&gt; header;  
      private List&lt;SurveyRow&gt; rows;
  
      public List&lt;SurveyColumn&gt; getHeader() {
          return header;
      }
  
      public List&lt;SurveyRow&gt; getRows() {
          return rows;
      }
  
      public void setHeader(List&lt;SurveyColumn&gt; header) {
          this.header = header;
      }
  
      public void setRows(List&lt;SurveyRow&gt; rows) {
          this.rows = rows;
      }
  
  }
  
  class SurveyColumn {
  
      private FieldType fieldType;
      private boolean readOnly;
      private String headerValue;
  
      public static class Builder {
          private FieldType fieldType;
          private boolean readOnly;
          private String headerValue;
  
          public Builder withFieldType(FieldType fieldType) {
              this.fieldType = fieldType;
              return this;
          }
  
          public Builder withReadOnly(boolean readOnly) {
              this.readOnly = readOnly;
              return this;
          }
  
          public Builder withHeaderValue(String headerValue) {
              this.headerValue = headerValue;
              return this;
          }
  
          public SurveyColumn build() {
              return new SurveyColumn(fieldType, readOnly, headerValue);
          }
      }
  
      public SurveyColumn(FieldType fieldType, boolean readOnly, String headerValue) {
          this.fieldType = fieldType;
          this.readOnly = readOnly;
          this.headerValue = headerValue;
      }
  }
  
  class SurveyRow {
  
      public static class Builder {
          private String[] fieldValues;
  
          public Builder withFieldValues(String[] fieldValues) {
              this.fieldValues = fieldValues;
              return this;
          }
  
          public SurveyRow build() {
              return new SurveyRow(fieldValues);
          }
      }
  
      private String[] fieldValues;
  
      public SurveyRow(String[] fieldValues) {
          this.fieldValues = fieldValues;
      }
  }
  
  public class TestGson {
  
      public static void main(String[] args) {
  
          SurveyFields fields = new SurveyFields();
  
          fields.setHeader(Arrays.asList(new SurveyColumn[] {
                  new SurveyColumn.Builder().withHeaderValue("name").withFieldType(FieldType.STRING).withReadOnly(true)
                          .build(),
                  new SurveyColumn.Builder().withHeaderValue("description").withFieldType(FieldType.STRING)
                          .withReadOnly(true).build() }));
  
          fields.setRows(Arrays.asList(new SurveyRow[] {
                  new SurveyRow.Builder().withFieldValues(new String[] { "engine", "this is an engine" }).build(),
                  new SurveyRow.Builder().withFieldValues(new String[] { "engine", "this is an engine" }).build(),
                  new SurveyRow.Builder().withFieldValues(new String[] { "engine", "this is an engine" }).build(),
                  new SurveyRow.Builder().withFieldValues(new String[] { "engine", "this is an engine" }).build()
          }));
  
          Gson gson = new Gson();
          System.out.println(gson.toJson(fields));
  
      }
  
  }
  </code></pre>
  
  <p>How can I structure my POJO's to match the expected JSON output?</p>