Visitar URL original
去除 fastjson 并支持各种 JSON 库 by TommyLemon · Pull Request #810 · APIJSON/APIJSON · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
解决 远程函数 报错 JSON 转换类型不匹配
  • Loading branch information
TommyLemon committed Mar 30, 2025
commit aa35bf6aa755287c6659e7f178578586497d702f
3 changes: 3 additions & 0 deletions APIJSONORM/src/main/java/apijson/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* @author Lemon
*/
public class JSON {
public static Class<?> JSON_OBJECT_CLASS = JSONObject.class;
public static Class<?> JSON_ARRAY_CLASS = JSONArray.class;

static final String TAG = "JSON";

public static JSONParser<? extends Map<String, Object>, ? extends List<Object>> DEFAULT_JSON_PARSER = new JSONParser<JSONObject, JSONArray>() {
Expand Down
14 changes: 7 additions & 7 deletions APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public <T extends Object> List<T> getArgList(String path) {
*/
public <T extends Object> List<T> getArgList(String path, Class<T> clazz) {
String s = getArgStr(path);
return JSON.parseArray(s, clazz, (JSONParser<? extends Map<String, Object>, List<Object>>) this);
return JSON.parseArray(s, clazz);
}

/**根据路径取值
Expand Down Expand Up @@ -349,13 +349,13 @@ public static <T extends Object> T getArgValue(Map<String, Object> obj, String p
if (v instanceof Map) {
return (T) v;
}
return (T) JSON.parseObject(JSON.toJSONString(v));
return (T) JSON.parseObject(v);
}
if (List.class.isAssignableFrom(clazz)) {
if (v instanceof List) {
return (T) v;
}
return (T) JSON.parseArray(JSON.toJSONString(v));
return (T) JSON.parseArray(v);
}
// Fallback to string conversion
return (T) v;
Expand Down Expand Up @@ -386,7 +386,7 @@ public Object invoke(@NotNull String function, @NotNull M current, boolean conta
throw new IllegalArgumentException("字符 " + function + " 不合法!");
}

return invoke(this, function, (JSONObject) current, containRaw);
return invoke(this, function, current, containRaw);
}

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

values = new Object[length + 1];
values[0] = request;
Expand Down Expand Up @@ -940,13 +940,13 @@ public <V> V getArgVal(String key, Class<V> clazz, boolean defaultValue) throws
if (obj instanceof Map) {
return (V) obj;
}
return (V) JSON.parseObject(JSON.toJSONString(obj));
return (V) JSON.parseObject(obj);
}
if (List.class.isAssignableFrom(clazz)) {
if (obj instanceof List) {
return (V) obj;
}
return (V) JSON.parseArray(JSON.toJSONString(obj));
return (V) JSON.parseArray(obj);
}
// Fallback to string conversion
return (V) obj;
Expand Down