/**
  * Deserialize the list of sheets
  *
  * @param crosstabDefinitionJSON
  * @param crosstabDefinition
  * @throws Exception
  */
 private void deserializeSheets(
     JSONObject crosstabDefinitionJSON, WorkSheetDefinition crosstabDefinition) throws Exception {
   JSONArray sheetsJSON = crosstabDefinitionJSON.getJSONArray(WorkSheetSerializationUtils.SHEETS);
   List<Sheet> workSheets = new ArrayList<Sheet>();
   for (int i = 0; i < sheetsJSON.length(); i++) {
     workSheets.add(deserializeSheet(sheetsJSON.getJSONObject(i)));
   }
   crosstabDefinition.setSheets(workSheets);
 }
 private void deserializeGlobalFilters(
     JSONObject workSheetDefinitionJSON, WorkSheetDefinition workSheetDefinition)
     throws Exception {
   JSONArray gfJSON =
       workSheetDefinitionJSON.getJSONArray(WorkSheetSerializationUtils.GLOBAL_FILTERS);
   List<Attribute> globalFilters = new ArrayList<Attribute>();
   for (int i = 0; i < gfJSON.length(); i++) {
     globalFilters.add(deserializeAttribute(gfJSON.getJSONObject(i)));
   }
   workSheetDefinition.setGlobalFilters(globalFilters);
 }
  private void deserializeOptions(
      JSONObject workSheetDefinitionJSON, WorkSheetDefinition workSheetDefinition)
      throws Exception {
    JSONArray optionsJSON =
        workSheetDefinitionJSON.getJSONArray(WorkSheetSerializationUtils.FIELDS_OPTIONS);
    WorksheetFieldsOptions options = new WorksheetFieldsOptions();
    for (int i = 0; i < optionsJSON.length(); i++) {

      JSONObject aField = optionsJSON.getJSONObject(i);
      String nature = aField.getString("nature");
      Field field = null;
      if (nature.equals("postLineCalculated")
          || nature.equals("segment_attribute")
          || nature.equals("attribute")) {
        Attribute attribute =
            (Attribute)
                SerializationManager.deserialize(aField, "application/json", Attribute.class);
        field = attribute;
      } else {
        Measure measure =
            (Measure) SerializationManager.deserialize(aField, "application/json", Measure.class);
        field = measure;
      }

      JSONObject optionsForFieldJSON = aField.getJSONObject(WorkSheetSerializationUtils.OPTIONS);
      Iterator optionsForFieldKeysIt = optionsForFieldJSON.keys();
      List<FieldOption> fieldOptionList = new ArrayList<FieldOption>();
      while (optionsForFieldKeysIt.hasNext()) {
        String name = (String) optionsForFieldKeysIt.next();
        Object value = optionsForFieldJSON.get(name);
        FieldOption o = WorksheetFieldsOptions.createOption(field, name, value);
        fieldOptionList.add(o);
      }

      FieldOptions fieldOptions = new FieldOptions();
      fieldOptions.setField(field);
      fieldOptions.setOptions(fieldOptionList);

      options.addFieldOptions(fieldOptions);
    }
    workSheetDefinition.setFieldsOptions(options);
  }