Search in sources :

Example 1 with IWrappingContext

use of org.sablo.specification.property.IWrappingContext in project servoy-client by Servoy.

the class DatasetPropertyType method toJSON.

@Override
public JSONWriter toJSON(JSONWriter writer, String key, IDataSet value, PropertyDescription propertyDescription, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
    JSONUtils.addKeyIfPresent(writer, key);
    if (value == null) {
        return writer.value(null);
    }
    writer.array();
    if (value.getColumnCount() > 0) {
        DatasetConfig datasetConfig = (DatasetConfig) propertyDescription.getConfig();
        String[] columnNames = value.getColumnNames();
        if (datasetConfig.isIncludeColumnNames() && columnNames != null) {
            writer.array();
            for (String columnName : columnNames) {
                writer.value(columnName);
            }
            writer.endArray();
        }
        for (int i = 0; i < value.getRowCount(); i++) {
            writer.array();
            Object[] row = value.getRow(i);
            PropertyDescription pd;
            for (int j = 0; j < row.length; j++) {
                pd = datasetConfig.getColumnType(columnNames[j]);
                if (pd != null) {
                    Object v;
                    if (pd.getType() instanceof IWrapperType<?, ?>) {
                        IWrappingContext c = (dataConverterContext instanceof IWrappingContext ? (IWrappingContext) dataConverterContext : new WrappingContext(dataConverterContext.getWebObject(), pd.getName()));
                        v = ((IWrapperType<Object, ?>) pd.getType()).wrap(row[j], null, pd, c);
                    } else {
                        v = row[j];
                    }
                    FullValueToJSONConverter.INSTANCE.toJSONValue(writer, null, v, pd, clientConversion, null);
                } else {
                    writer.value(row[j]);
                }
            }
            writer.endArray();
        }
    }
    writer.endArray();
    return writer;
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) IWrappingContext(org.sablo.specification.property.IWrappingContext) WrappingContext(org.sablo.specification.property.WrappingContext) IWrappingContext(org.sablo.specification.property.IWrappingContext) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IWrapperType(org.sablo.specification.property.IWrapperType)

Aggregations

ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)1 JSONObject (org.json.JSONObject)1 PropertyDescription (org.sablo.specification.PropertyDescription)1 IWrapperType (org.sablo.specification.property.IWrapperType)1 IWrappingContext (org.sablo.specification.property.IWrappingContext)1 WrappingContext (org.sablo.specification.property.WrappingContext)1