Skip to content

Commit 2ac3b48

Browse files
committed
JSONRequest.put 减少不必要的转换及打印异常日志
1 parent 4087861 commit 2ac3b48

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/main/java/apijson/fastjson2/JSONRequest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,19 @@ public Object put(String key, Object value) {
8787
}
8888

8989
Object target = null;
90-
try {
91-
target = JSON.parse(value);
92-
} catch (Exception e) {
93-
// nothing
94-
e.printStackTrace();
95-
}
90+
Class<?> cls = value.getClass();
91+
if ( ! (value instanceof Map<?, ?> || value instanceof Collection<?> || JSON.isBoolOrNumOrStr(value))) {
92+
try {
93+
target = JSON.parse(value);
94+
} catch (Exception e) {
95+
// nothing
96+
e.printStackTrace();
97+
}
98+
}
9699
// if (target == null) { // "tag":"User" 报错
97100
// return null;
98101
// }
99-
return super.put(StringUtil.isNotEmpty(key, true) ? key : value.getClass().getSimpleName() //must handle key here
102+
return super.put(StringUtil.isNotEmpty(key, true) ? key : cls.getSimpleName() //must handle key here
100103
, target == null ? value : target);
101104
}
102105

0 commit comments

Comments
 (0)