/**
   * Gets a new JSON object from the bean
   *
   * @param bean T object
   * @return a new JSON object
   */
  protected String newJsonRow(T bean) {
    JSONStringer stringer = new JSONStringer();

    try {
      stringer.object();

      for (IColumn column : this.columns) {
        if (column instanceof PropertyColumn) {
          PropertyColumn pc = (PropertyColumn) column;
          stringer.key(pc.getField()).value(pc.getValue(bean));
        }
      }

      stringer.endObject();
    } catch (JSONException e) {
      throw new ConversionException(e);
    }

    return stringer.toString();
  }
Example #2
0
  private CharSequence hashToJson(HashMap<String, Object> dict) {
    try {
      JSONStringer writer = new JSONStringer();
      writer.object();

      if (dict != null) {
        for (String key : dict.keySet()) {
          Object value = dict.get(key);
          if (value != null) {
            writer.key(key);
            writer.value(value);
          }
        }
      }

      writer.endObject();
      return writer.toString();
    } catch (JSONException e) {
      throw new RuntimeException("Could not convert HashMap object to Json", e);
    }
  }