|
30 | 30 | import com.alibaba.fastjson.JSONObject; |
31 | 31 |
|
32 | 32 | import apijson.JSON; |
| 33 | +import apijson.JSONRequest; |
33 | 34 | import apijson.JSONResponse; |
34 | 35 | import apijson.Log; |
35 | 36 | import apijson.NotNull; |
@@ -513,31 +514,53 @@ public JSONObject parseCorrectRequest(RequestMethod method, String tag, int vers |
513 | 514 | + "非开放请求必须是后端 Request 表中校验规则允许的操作!\n " + error + "\n如果需要则在 Request 表中新增配置!"); |
514 | 515 | } |
515 | 516 |
|
516 | | - JSONObject target = object; |
517 | | - if (object.containsKey(tag) == false) { //tag 是 Table 名或 Table[] |
| 517 | + //获取指定的JSON结构 >>>>>>>>>>>>>> |
| 518 | + JSONObject target = wrapRequest(object, tag, false); |
| 519 | + |
| 520 | + //JSONObject clone 浅拷贝没用,Structure.parse 会导致 structure 里面被清空,第二次从缓存里取到的就是 {} |
| 521 | + return getVerifier().verifyRequest(method, name, target, request, maxUpdateCount, getGlobleDatabase(), getGlobleSchema(), creator); |
| 522 | + } |
518 | 523 |
|
519 | | - boolean isArrayKey = tag.endsWith(":[]"); // JSONRequest.isArrayKey(tag); |
520 | | - String key = isArrayKey ? tag.substring(0, tag.length() - 3) : tag; |
521 | 524 |
|
522 | | - if (apijson.JSONObject.isTableKey(key)) { |
523 | | - if (isArrayKey) { //自动为 tag = Comment:[] 的 { ... } 新增键值对 "Comment[]":[] 为 { "Comment[]":[], ... } |
524 | | - target.put(key + "[]", new JSONArray()); |
525 | | - } |
526 | | - else { //自动为 tag = Comment 的 { ... } 包一层为 { "Comment": { ... } } |
527 | | - target = new JSONObject(true); |
528 | | - target.put(tag, object); |
| 525 | + /**自动根据 tag 是否为 TableKey 及是否被包含在 object 内来决定是否包装一层,改为 { tag: object, "tag": tag } |
| 526 | + * @param object |
| 527 | + * @param tag |
| 528 | + * @return |
| 529 | + */ |
| 530 | + public static JSONObject wrapRequest(JSONObject object, String tag, boolean putTag) { |
| 531 | + if (object == null || object.containsKey(tag)) { //tag 是 Table 名或 Table[] |
| 532 | + if (putTag) { |
| 533 | + if (object == null) { |
| 534 | + object = new JSONObject(true); |
529 | 535 | } |
| 536 | + object.put(JSONRequest.KEY_TAG, tag); |
530 | 537 | } |
| 538 | + return object; |
531 | 539 | } |
532 | 540 |
|
533 | | - //获取指定的JSON结构 >>>>>>>>>>>>>> |
534 | | - |
| 541 | + boolean isDiffArrayKey = tag.endsWith(":[]"); |
| 542 | + boolean isArrayKey = isDiffArrayKey || JSONRequest.isArrayKey(tag); |
| 543 | + String key = isArrayKey ? tag.substring(0, tag.length() - (isDiffArrayKey ? 3 : 2)) : tag; |
535 | 544 |
|
536 | | - //JSONObject clone 浅拷贝没用,Structure.parse 会导致 structure 里面被清空,第二次从缓存里取到的就是 {} |
537 | | - return getVerifier().verifyRequest(method, name, target, request, maxUpdateCount, getGlobleDatabase(), getGlobleSchema(), creator); |
| 545 | + JSONObject target = object; |
| 546 | + if (apijson.JSONObject.isTableKey(key)) { |
| 547 | + if (isDiffArrayKey) { //自动为 tag = Comment:[] 的 { ... } 新增键值对 "Comment[]":[] 为 { "Comment[]":[], ... } |
| 548 | + target.put(key + "[]", new JSONArray()); |
| 549 | + } |
| 550 | + else { //自动为 tag = Comment 的 { ... } 包一层为 { "Comment": { ... } } |
| 551 | + target = new JSONObject(true); |
| 552 | + target.put(tag, object); |
| 553 | + } |
| 554 | + } |
| 555 | + |
| 556 | + if (putTag) { |
| 557 | + target.put(JSONRequest.KEY_TAG, tag); |
| 558 | + } |
| 559 | + |
| 560 | + return target; |
538 | 561 | } |
539 | 562 |
|
540 | | - |
| 563 | + |
541 | 564 | /**新建带状态内容的JSONObject |
542 | 565 | * @param code |
543 | 566 | * @param msg |
|
0 commit comments