Skip to content

Commit 96344fa

Browse files
committed
Server:解决数组内无意义的嵌套浪费性能:key[]:{} 内第一个 key:{} 必须是主表对象 TableKey:{} , 且所有 key:{} 都只能是 表对象 TableKey:{} 或 数组对象 key[]:{}
1 parent d5995fb commit 96344fa

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,28 @@ public boolean onParse(@NotNull String key, @NotNull Object value) throws Except
365365
@Override
366366
public JSON onChildParse(int index, String key, JSONObject value) throws Exception {
367367
boolean isFirst = index <= 0;
368+
boolean isMain = isFirst && type == TYPE_ITEM;
369+
368370
JSON child;
369371
boolean isEmpty;
370-
372+
371373
if (zuo.biao.apijson.JSONObject.isArrayKey(key)) {//APIJSON Array
374+
if (isMain) {
375+
throw new IllegalArgumentException(parentPath + "/" + key + ":{} 不合法!"
376+
+ "数组 []:{} 中第一个 key:{} 必须是主表 TableKey:{} !不能为 arrayKey[]:{} !");
377+
}
378+
372379
child = parser.onArrayParse(value, path, key);
373380
isEmpty = child == null || ((JSONArray) child).isEmpty();
374381
}
375382
else {//APIJSON Object
376-
child = parser.onObjectParse(value, path, key
377-
, isFirst && type == TYPE_ITEM ? arrayConfig.setType(SQLConfig.TYPE_ITEM_CHILD_0) : null);
383+
if (type == TYPE_ITEM && JSONRequest.isTableKey(Pair.parseEntry(key, true).getKey()) == false) {
384+
throw new IllegalArgumentException(parentPath + "/" + key + ":{} 不合法!"
385+
+ "数组 []:{} 中每个 key:{} 都必须是表 TableKey:{} 或 数组 arrayKey[]:{} !");
386+
}
387+
388+
child = parser.onObjectParse(value, path, key, isMain ? arrayConfig.setType(SQLConfig.TYPE_ITEM_CHILD_0) : null);
389+
378390
isEmpty = child == null || ((JSONObject) child).isEmpty();
379391
if (isFirst && isEmpty) {
380392
invalidate();

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,13 @@ public JSONArray onArrayParse(final JSONObject request, String parentPath, Strin
663663

664664
//Table<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
665665
JSONArray response = new JSONArray();
666-
JSONObject parent;
667666
SQLConfig config = createSQLConfig()
668667
.setMethod(requestMethod)
669668
.setCount(size)
670669
.setPage(page)
671670
.setQuery(query);
671+
672+
JSONObject parent;
672673
//生成size个
673674
for (int i = 0; i < size; i++) {
674675
parent = onObjectParse(request, path, "" + i, config.setType(SQLConfig.TYPE_ITEM).setPosition(i));

0 commit comments

Comments
 (0)