Skip to content

Commit 3e86b09

Browse files
committed
解决 PUT 请求传 @key:[] 被当成表字段然后解析报错
1 parent d7905ff commit 3e86b09

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,36 +222,42 @@ public AbstractObjectParser parse() throws Exception {
222222
key = entry.getKey();
223223

224224
try {
225-
if (value instanceof JSONObject && key.startsWith("@") == false && key.endsWith("@") == false) { //JSONObject,往下一级提取
226-
if (childMap != null) {//添加到childMap,最后再解析
225+
if (key.startsWith("@") || key.endsWith("@")) {
226+
if (onParse(key, value) == false) {
227+
invalidate();
228+
}
229+
}
230+
else if (value instanceof JSONObject) { // JSONObject,往下一级提取
231+
if (childMap != null) { // 添加到childMap,最后再解析
227232
childMap.put(key, (JSONObject)value);
228233
}
229-
else { //直接解析并替换原来的,[]:{} 内必须直接解析,否则会因为丢掉count等属性,并且total@:"/[]/total"必须在[]:{} 后!
234+
else { // 直接解析并替换原来的,[]:{} 内必须直接解析,否则会因为丢掉count等属性,并且total@:"/[]/total"必须在[]:{} 后!
230235
response.put(key, onChildParse(index, key, (JSONObject)value));
231236
index ++;
232237
}
233238
}
234-
else if ((method == POST || method == PUT) && value instanceof JSONArray && JSONRequest.isTableArray(key)) { //JSONArray,批量新增或修改,往下一级提取
239+
else if ((method == POST || method == PUT) && value instanceof JSONArray
240+
&& JSONRequest.isTableArray(key)) { // JSONArray,批量新增或修改,往下一级提取
235241
onTableArrayParse(key, (JSONArray) value);
236242
}
237243
else if (method == PUT && value instanceof JSONArray
238-
&& (whereList == null || whereList.contains(key) == false)) { //PUT JSONArray
244+
&& (whereList == null || whereList.contains(key) == false)) { // PUT JSONArray
239245
onPUTArrayParse(key, (JSONArray) value);
240246
}
241-
else {//JSONArray或其它Object,直接填充
247+
else { // JSONArray或其它Object,直接填充
242248
if (onParse(key, value) == false) {
243249
invalidate();
244250
}
245251
}
246252
} catch (Exception e) {
247253
if (tri == false) {
248-
throw e;//不忽略错误,抛异常
254+
throw e; // 不忽略错误,抛异常
249255
}
250-
invalidate();//忽略错误,还原request
256+
invalidate(); // 忽略错误,还原request
251257
}
252258
}
253259

254-
//非Table内的函数会被滞后在onChildParse后调用! onFunctionResponse("-");
260+
// 非Table内的函数会被滞后在onChildParse后调用! onFunctionResponse("-");
255261
}
256262

257263
if (isTable) {

0 commit comments

Comments
 (0)