private SheetContent deserializeContent(JSONObject sheetJSON) throws Exception {
   SheetContent toReturn = null;
   JSONObject content = sheetJSON.optJSONObject(WorkSheetSerializationUtils.CONTENT);
   if (content == null) {
     logger.warn(
         "Sheet content not found for sheet ["
             + sheetJSON.getString(WorkSheetSerializationUtils.NAME)
             + "].");
     return null;
   }
   String designer = content.getString(WorkSheetSerializationUtils.DESIGNER);
   if (WorkSheetSerializationUtils.DESIGNER_PIVOT.equals(designer)) {
     toReturn =
         (CrosstabDefinition)
             SerializationManager.deserialize(
                 content.getJSONObject(WorkSheetSerializationUtils.CROSSTABDEFINITION),
                 "application/json",
                 CrosstabDefinition.class);
     ((CrosstabDefinition) toReturn).setStatic(false);
   } else if (WorkSheetSerializationUtils.DESIGNER_STATIC_PIVOT.equals(designer)) {
     toReturn =
         (CrosstabDefinition)
             SerializationManager.deserialize(
                 content.getJSONObject(WorkSheetSerializationUtils.CROSSTABDEFINITION),
                 "application/json",
                 CrosstabDefinition.class);
     ((CrosstabDefinition) toReturn).setStatic(true);
   } else if (WorkSheetSerializationUtils.DESIGNER_TABLE.equals(designer)) {
     toReturn = deserializeTable(content);
   } else {
     toReturn = deserializeChart(content);
   }
   return toReturn;
 }
  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);
  }
  private SheetContent deserializeChart(JSONObject content)
      throws JSONException, SerializationException {
    SheetContent toReturn;
    ChartDefinition chart = new ChartDefinition();

    JSONObject categoryJSON = content.optJSONObject(WorkSheetSerializationUtils.CATEGORY);
    if (categoryJSON != null) {
      Attribute category =
          (Attribute)
              SerializationManager.deserialize(categoryJSON, "application/json", Attribute.class);
      chart.setCategory(category);
    }

    JSONObject groupingVariableJSON =
        content.optJSONObject(WorkSheetSerializationUtils.GROUPING_VARIABLE);
    if (groupingVariableJSON != null) {
      Attribute groupingVariable =
          (Attribute)
              SerializationManager.deserialize(
                  groupingVariableJSON, "application/json", Attribute.class);
      chart.setGroupingVariable(groupingVariable);
    }

    List<Serie> series = new ArrayList<Serie>();
    JSONArray seriesJSON = content.getJSONArray(WorkSheetSerializationUtils.SERIES);
    SerieJSONDeserializer deserialier = new SerieJSONDeserializer();
    for (int i = 0; i < seriesJSON.length(); i++) {
      JSONObject aSerie = seriesJSON.getJSONObject(i);
      Serie serie = deserialier.deserialize(aSerie);
      series.add(serie);
    }
    chart.setSeries(series);

    content.remove(WorkSheetSerializationUtils.CATEGORY);
    content.remove(WorkSheetSerializationUtils.SERIES);
    chart.setConfig(content);

    toReturn = chart;
    return toReturn;
  }
 private SheetContent deserializeTable(JSONObject content)
     throws JSONException, SerializationException {
   SheetContent toReturn;
   TableDefinition table = new TableDefinition();
   JSONArray fields = content.getJSONArray(WorkSheetSerializationUtils.VISIBLE_SELECT_FIELDS);
   for (int i = 0; i < fields.length(); i++) {
     JSONObject aField = fields.getJSONObject(i);
     String nature = aField.getString("nature");
     if (nature.equals("postLineCalculated")
         || nature.equals("segment_attribute")
         || nature.equals("attribute")) {
       Attribute attribute =
           (Attribute)
               SerializationManager.deserialize(aField, "application/json", Attribute.class);
       table.addField(attribute);
     } else {
       Measure measure =
           (Measure) SerializationManager.deserialize(aField, "application/json", Measure.class);
       table.addField(measure);
     }
   }
   toReturn = table;
   return toReturn;
 }
 private Attribute deserializeAttribute(JSONObject jsonObject) throws SerializationException {
   Attribute attribute =
       (Attribute)
           SerializationManager.deserialize(jsonObject, "application/json", Attribute.class);
   return attribute;
 }