Tencent/APIJSON · error · UnsupportedDataTypeException

{}:value 中value不合法!远程函数 key():{} 中的 arg 对应的值类型只能是 [Boolean,

Error message

{}:value 中value不合法!远程函数 key():{} 中的 arg 对应的值类型只能是 [Boolean, Number, String, JSONMap, JSONList] 中的一种!

What it means

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.

Source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java:656

				else if (v instanceof Number) {
					types[i] = Number.class;
				}
				else if (v instanceof String) {
					types[i] = String.class;
				}
				else if (v instanceof Map) { // 泛型兼容? // JSONMap
					types[i] = Map.class;
					//性能比较差
                    //values[i] = TypeUtils.cast(v, Map.class, ParserConfig.getGlobalInstance());
				}
				else if (v instanceof Collection) { // 泛型兼容? // JSONList
					types[i] = List.class;
					//性能比较差
					List list = new ArrayList<>((Collection) v);
                    values[i] = list; // TypeUtils.cast(v, List.class, ParserConfig.getGlobalInstance());
				}
				else {
					throw new UnsupportedDataTypeException(keys[i] + ":value 中value不合法!远程函数 key():"
                            + function + " 中的 arg 对应的值类型只能是 [Boolean, Number, String, JSONMap, JSONList] 中的一种!");
				}
			}
		}
		else {
			Class<? extends Map> cls = JSON.createJSONObject().getClass();
			types = new Class<?>[length + 1];
			//types[0] = Object.class; // 泛型擦除 JSON.JSON_OBJECT_CLASS;
			types[0] = cls;

			values = new Object[length + 1];
			values[0] = request;

			for (int i = 0; i < length; i++) {
				types[i + 1] = String.class;
				values[i + 1] = keys[i];
			}
		}

View on GitHub (pinned to 5284052872)

Solutions

  1. 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.
  2. Convert non-JSON Java objects (Date, enums, beans) to String/Number/Map before the request reaches the function parser.
  3. Change the remote function signature so it takes the value under a JSON-native key, and do custom type conversion inside the function body.

Example fix

// before
request.put("since", new Date()); // then 'key()': 'filter(since)'
// after
request.put("since", System.currentTimeMillis()); // long -> Number is accepted
Defensive patterns

Strategy: type-guard

Validate before calling

for (String k : keysInFunction) {
  Object v = request.get(k);
  if (!(v == null || v instanceof Boolean || v instanceof Number || v instanceof String || v instanceof Map || v instanceof Collection)) {
    throw new IllegalArgumentException("arg " + k + " must be Boolean/Number/String/JSONMap/JSONList");
  }
}

Type guard

function isJsonArgType(v: unknown): boolean {
  const t = typeof v;
  return v === null || t === 'boolean' || t === 'number' || t === 'string' || Array.isArray(v) || (t === 'object' && v !== null);
}

Try / catch

try { invokeRemoteFunction(fn, request); } catch (UnsupportedDataTypeException e) { // identify the offending key from the message prefix, convert it to a JSON-native type, retry }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14). Data as JSON: /api/errors/062b9a9c44d9dc4e. Report an issue: GitHub.