Skip to content

Commit aa35bf6

Browse files
committed
解决 远程函数 报错 JSON 转换类型不匹配
1 parent e5001aa commit aa35bf6

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

APIJSONORM/src/main/java/apijson/JSON.java

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* @author Lemon
1414
*/
1515
public class JSON {
16+
public static Class<?> JSON_OBJECT_CLASS = JSONObject.class;
17+
public static Class<?> JSON_ARRAY_CLASS = JSONArray.class;
18+
1619
static final String TAG = "JSON";
1720

1821
public static JSONParser<? extends Map<String, Object>, ? extends List<Object>> DEFAULT_JSON_PARSER = new JSONParser<JSONObject, JSONArray>() {

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public <T extends Object> List<T> getArgList(String path) {
265265
*/
266266
public <T extends Object> List<T> getArgList(String path, Class<T> clazz) {
267267
String s = getArgStr(path);
268-
return JSON.parseArray(s, clazz, (JSONParser<? extends Map<String, Object>, List<Object>>) this);
268+
return JSON.parseArray(s, clazz);
269269
}
270270

271271
/**根据路径取值
@@ -349,13 +349,13 @@ public static <T extends Object> T getArgValue(Map<String, Object> obj, String p
349349
if (v instanceof Map) {
350350
return (T) v;
351351
}
352-
return (T) JSON.parseObject(JSON.toJSONString(v));
352+
return (T) JSON.parseObject(v);
353353
}
354354
if (List.class.isAssignableFrom(clazz)) {
355355
if (v instanceof List) {
356356
return (T) v;
357357
}
358-
return (T) JSON.parseArray(JSON.toJSONString(v));
358+
return (T) JSON.parseArray(v);
359359
}
360360
// Fallback to string conversion
361361
return (T) v;
@@ -386,7 +386,7 @@ public Object invoke(@NotNull String function, @NotNull M current, boolean conta
386386
throw new IllegalArgumentException("字符 " + function + " 不合法!");
387387
}
388388

389-
return invoke(this, function, (JSONObject) current, containRaw);
389+
return invoke(this, function, current, containRaw);
390390
}
391391

392392
/**反射调用
@@ -657,7 +657,7 @@ else if (v instanceof Collection) { // 泛型兼容? // JSONArray
657657
}
658658
else {
659659
types = new Class<?>[length + 1];
660-
types[0] = JSONObject.class;
660+
types[0] = JSON.JSON_OBJECT_CLASS;
661661

662662
values = new Object[length + 1];
663663
values[0] = request;
@@ -940,13 +940,13 @@ public <V> V getArgVal(String key, Class<V> clazz, boolean defaultValue) throws
940940
if (obj instanceof Map) {
941941
return (V) obj;
942942
}
943-
return (V) JSON.parseObject(JSON.toJSONString(obj));
943+
return (V) JSON.parseObject(obj);
944944
}
945945
if (List.class.isAssignableFrom(clazz)) {
946946
if (obj instanceof List) {
947947
return (V) obj;
948948
}
949-
return (V) JSON.parseArray(JSON.toJSONString(obj));
949+
return (V) JSON.parseArray(obj);
950950
}
951951
// Fallback to string conversion
952952
return (V) obj;

0 commit comments

Comments
 (0)