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;
}
Aggregations