APIJSON 是一种基于 JSON 的数据交换格式,最近在使用时发现 数据为null的属性会自动过滤,导致返回的结果不完整,查看源码发现是故意过滤了 null值的属性,至于为什么默认这么处理还不清楚,暂时做个记录。
修改 AbstractSQLExecutor 类的 onPutColumn 方法即可:
/**table.put(rsmd.getColumnLabel(i), rs.getObject(i));
* @param config
* @param rs
* @param rsmd
* @param tablePosition 从0开始
* @param table
* @param columnIndex 从1开始
* @param childMap
* @return result
* @throws Exception
*/
protected JSONObject onPutColumn(@NotNull SQLConfig config, @NotNull ResultSet rs, @NotNull ResultSetMetaData rsmd
, final int tablePosition, @NotNull JSONObject table, final int columnIndex, Join join, Map<String, JSONObject> childMap) throws Exception {
if (table == null) { // 对应副表 viceSql 不能生成正常 SQL, 或者是 ! - Outer, ( - ANTI JOIN 的副表这种不需要缓存及返回的数据
Log.i(TAG, "onPutColumn table == null >> return table;");
return table;
}
if (isHideColumn(config, rs, rsmd, tablePosition, table, columnIndex, childMap)) {
Log.i(TAG, "onPutColumn isHideColumn(config, rs, rsmd, tablePosition, table, columnIndex, childMap) >> return table;");
return table;
}
String label = getKey(config, rs, rsmd, tablePosition, table, columnIndex, childMap);
Object value = getValue(config, rs, rsmd, tablePosition, table, columnIndex, label, childMap);
// 主表必须 put 至少一个 null 进去,否则全部字段为 null 都不 put 会导致中断后续正常返回值
// if (value != null || (join == null && table.isEmpty())) {
// table.put(label, value);
// }
table.put(label, value);
return table;
}