-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update AbstractObjectParser.java #119
Merged
TommyLemon
merged 2 commits into
Tencent:master
from
zhoulingfengofcd:zhoulingfengofcd-patch-1
Feb 27, 2020
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,8 +240,33 @@ public AbstractObjectParser parse() throws Exception { | |
response.put(key, onChildParse(index, key, (JSONObject)value)); | ||
index ++; | ||
} | ||
} | ||
else if (method == PUT && value instanceof JSONArray | ||
} else if (value instanceof JSONArray && method == POST && | ||
key.startsWith("@") == false && key.endsWith("@") == false) {//JSONArray,批量新增,往下一级提取 | ||
JSONArray valueArray = (JSONArray)value; | ||
|
||
for (int i = 0; i < valueArray.size(); i++) { | ||
if (childMap != null) {//添加到childMap,最后再解析 | ||
childMap.put(key, valueArray.getJSONObject(i)); | ||
} | ||
else {//直接解析并替换原来的,[]:{} 内必须直接解析,否则会因为丢掉count等属性,并且total@:"/[]/total"必须在[]:{} 后! | ||
JSONObject result = (JSONObject)onChildParse(index, key, valueArray.getJSONObject(i)); | ||
//合并结果 | ||
JSONObject before = (JSONObject)response.get(key); | ||
if(result.get("code").equals(200)){ | ||
if(before!=null){ | ||
before.put("count",before.getInteger("count")+result.getInteger("count")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "count" 已有 JSONRequst.KEY_COUNT 常量,建议替换 |
||
response.put(key, before); | ||
}else{ | ||
response.put(key, result); | ||
} | ||
} else { | ||
//只要有一条失败,则抛出异常,全部失败 | ||
throw new RuntimeException(key + "," + valueArray.getJSONObject(i) +",新增失败!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议根据 JSONResponse.KEY_CODE 及 JSONResponse.KEY_MSG 改为更准确的 Exeption,方便排查错误 |
||
} | ||
} | ||
} | ||
index ++; | ||
} else if (method == PUT && value instanceof JSONArray | ||
&& (whereList == null || whereList.contains(key) == false)) {//PUT JSONArray | ||
onPUTArrayParse(key, (JSONArray) value); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POST 未被 import 进来直接使用,编译报错