{"record":{"id":"062b9a9c44d9dc4e","repo":"Tencent/APIJSON","slug":"value-value-key-arg","errorCode":null,"errorMessage":"{}:value 中value不合法！远程函数 key():{} 中的 arg 对应的值类型只能是 [Boolean, Number, String, JSONMap, JSONList] 中的一种！","messagePattern":"(.+?):value 中value不合法！远程函数 key\\(\\):(.+?) 中的 arg 对应的值类型只能是 \\[Boolean, Number, String, JSONMap, JSONList\\] 中的一种！","errorType":"validation","errorClass":"UnsupportedDataTypeException","httpStatus":null,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java","lineNumber":656,"sourceCode":"\t\t\t\telse if (v instanceof Number) {\n\t\t\t\t\ttypes[i] = Number.class;\n\t\t\t\t}\n\t\t\t\telse if (v instanceof String) {\n\t\t\t\t\ttypes[i] = String.class;\n\t\t\t\t}\n\t\t\t\telse if (v instanceof Map) { // 泛型兼容？ // JSONMap\n\t\t\t\t\ttypes[i] = Map.class;\n\t\t\t\t\t//性能比较差\n                    //values[i] = TypeUtils.cast(v, Map.class, ParserConfig.getGlobalInstance());\n\t\t\t\t}\n\t\t\t\telse if (v instanceof Collection) { // 泛型兼容？ // JSONList\n\t\t\t\t\ttypes[i] = List.class;\n\t\t\t\t\t//性能比较差\n\t\t\t\t\tList list = new ArrayList<>((Collection) v);\n                    values[i] = list; // TypeUtils.cast(v, List.class, ParserConfig.getGlobalInstance());\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new UnsupportedDataTypeException(keys[i] + \":value 中value不合法！远程函数 key():\"\n                            + function + \" 中的 arg 对应的值类型只能是 [Boolean, Number, String, JSONMap, JSONList] 中的一种！\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tClass<? extends Map> cls = JSON.createJSONObject().getClass();\n\t\t\ttypes = new Class<?>[length + 1];\n\t\t\t//types[0] = Object.class; // 泛型擦除 JSON.JSON_OBJECT_CLASS;\n\t\t\ttypes[0] = cls;\n\n\t\t\tvalues = new Object[length + 1];\n\t\t\tvalues[0] = request;\n\n\t\t\tfor (int i = 0; i < length; i++) {\n\t\t\t\ttypes[i + 1] = String.class;\n\t\t\t\tvalues[i + 1] = keys[i];\n\t\t\t}\n\t\t}","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java#L638-L674","documentation":"Thrown when building argument type/value arrays for a remote function call: each argument fetched from the request must be a Boolean, Number, String, Map (JSONMap) or Collection (JSONList). Any other runtime type (e.g. a raw JSONObject subclass that is neither, a Date, or a custom object placed into the request map) falls into the else branch and throws UnsupportedDataTypeException with the offending key name.","triggerScenarios":"A remote function call 'key()': 'fun(argKey)' where request.get(\"argKey\") returns a type that is not Boolean/Number/String/Map/Collection — e.g. a java.util.Date, an enum, a byte[], or null handled by an earlier branch mismatch. Typical when server code inserts non-JSON-native objects into the request map before invoking the function parser.","commonSituations":"Backend code pre-populates the request JSONObject with typed Java objects (Date, BigDecimal is fine as Number, but custom beans are not); deserialized enums; or a client sends JSON that a custom deserializer turns into an exotic type.","solutions":["Ensure every argument referenced inside key(...) in the function string exists in the request as a plain JSON type: boolean, number, string, JSONObject or JSONArray.","Convert non-JSON Java objects (Date, enums, beans) to String/Number/Map before the request reaches the function parser.","Change the remote function signature so it takes the value under a JSON-native key, and do custom type conversion inside the function body."],"exampleFix":"// before\nrequest.put(\"since\", new Date()); // then 'key()': 'filter(since)'\n// after\nrequest.put(\"since\", System.currentTimeMillis()); // long -> Number is accepted","handlingStrategy":"type-guard","validationCode":"for (String k : keysInFunction) {\n  Object v = request.get(k);\n  if (!(v == null || v instanceof Boolean || v instanceof Number || v instanceof String || v instanceof Map || v instanceof Collection)) {\n    throw new IllegalArgumentException(\"arg \" + k + \" must be Boolean/Number/String/JSONMap/JSONList\");\n  }\n}","typeGuard":"function isJsonArgType(v: unknown): boolean {\n  const t = typeof v;\n  return v === null || t === 'boolean' || t === 'number' || t === 'string' || Array.isArray(v) || (t === 'object' && v !== null);\n}","tryCatchPattern":"try { invokeRemoteFunction(fn, request); } catch (UnsupportedDataTypeException e) { // identify the offending key from the message prefix, convert it to a JSON-native type, retry }","preventionTips":["Only place JSON-native types (bool/number/string/object/array) into the request map.","Convert Date/enum/bean values to strings or numbers before parsing.","Unit-test remote functions with each supported argument type."],"tags":["apijson","remote-function","type-check","argument-validation"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}