Skip to content

Commit 25dde1b

Browse files
committed
Server:新增支持Table嵌套Table(解决依赖解析问题)
1 parent 84900d3 commit 25dde1b

2 files changed

Lines changed: 25 additions & 18 deletions

File tree

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/ObjectParser.java‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public ObjectParser parse() throws Exception {
155155
key = entry.getKey();
156156

157157
if (value instanceof JSONObject) {//JSONObject,往下一级提取
158-
putChild(key, onChildParse(key, (JSON) value));
158+
putChild(key, (JSON) value);
159159
} else if (method == PUT && value instanceof JSONArray) {//PUT JSONArray
160160
onPUTArrayParse(key, (JSONArray) value);
161161
} else {//JSONArray或其它Object,直接填充
@@ -186,10 +186,10 @@ public ObjectParser parse() throws Exception {
186186
*/
187187
protected void putChild(String key, JSON child) throws Exception {
188188
if (child != null) {
189-
if (childMap != null) {
189+
if (childMap != null) {//添加到childMap,最后再解析
190190
childMap.put(key, child);
191-
} else {
192-
response.put(key, child);
191+
} else {//直接解析并替换原来的
192+
response.put(key, onChildParse(key, child));
193193
}
194194
}
195195
}
@@ -408,14 +408,21 @@ public ObjectParser executeSQL(int count, int page, int position) throws Excepti
408408
* @throws Exception
409409
*/
410410
public JSONObject response() throws Exception {
411-
if (sqlReponse != null) {
411+
if (sqlReponse == null || sqlReponse.isEmpty()) {
412+
if (isTableKey) {//Table自身都获取不到值,则里面的Child都无意义,不需要再解析
413+
return response;
414+
}
415+
} else {
412416
response.putAll(sqlReponse);
413417
}
414418

415-
if (customMap != null) {//把isTableKey时取出去的custom重新添加回来
419+
//把isTableKey时取出去的custom重新添加回来
420+
if (customMap != null) {
416421
response.putAll(customMap);
417422
}
418-
if (functionMap != null) {//解析函数function
423+
424+
//解析函数function
425+
if (functionMap != null) {
419426
Set<Entry<String, String>> functionSet = functionMap == null ? null : functionMap.entrySet();
420427
if (functionSet != null && functionSet.isEmpty() == false) {
421428
for (Entry<String, String> entry : functionSet) {
@@ -425,10 +432,16 @@ public JSONObject response() throws Exception {
425432
}
426433
}
427434

428-
if (childMap != null) {//把isTableKey时取出去的child重新添加回来
429-
response.putAll(childMap);
435+
//把isTableKey时取出去child解析后重新添加回来
436+
Set<Entry<String, JSON>> set = childMap == null ? null : childMap.entrySet();
437+
if (set != null) {
438+
for (Entry<String, JSON> entry : set) {
439+
if (entry != null) {
440+
response.put(entry.getKey(), onChildParse(entry.getKey(), entry.getValue()));
441+
}
442+
}
430443
}
431-
444+
432445
onComplete();
433446

434447
return response;

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Parser.java‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,6 @@ public com.alibaba.fastjson.JSON parseChild(@NotNull String path, @NotNull Strin
485485
return response;
486486
}
487487

488-
489-
/**
490-
* TODO 一次获取QueryConfig的方式减少了count-1次JSONObject->QueryConfig的过程,大幅提升了性能。
491-
* 但导致第一个Table位置被重新put到最后,并且需要重复getObject内的代码,目前[]中第一个Table还缺少对key()和自定义@key的支持。
492-
* 评估下[]:{FirstTableKey:{Table}}第一个Table需要使用这两种功能符的场景、频率和替代方式(外层?)
493-
*/
494488
/**获取对象数组,该对象数组处于parentObject内
495489
* @param parentPath parentObject的路径
496490
* @param name parentObject的key
@@ -501,8 +495,8 @@ public com.alibaba.fastjson.JSON parseChild(@NotNull String path, @NotNull Strin
501495
private JSONArray getArray(String parentPath, String name, final JSONObject request) throws Exception {
502496
Log.i(TAG, "\n\n\n getArray parentPath = " + parentPath
503497
+ "; name = " + name + "; request = " + JSON.toJSONString(request));
504-
if (isHeadMethod(requestMethod, true)) {
505-
throw new UnsupportedOperationException("HEAD、POST_HEAD方法不允许重复查询!不应该传 " + name + " 等key[]:{}!");
498+
if (isGetMethod(requestMethod, true) == false) {
499+
throw new UnsupportedOperationException("key[]:{}只支持GET类方法!不允许传 " + name + ":{} !");
506500
}
507501
if (request == null || request.isEmpty()) {//jsonKey-jsonValue条件
508502
return null;

0 commit comments

Comments
 (0)