Tencent/APIJSON · error · IllegalArgumentException
Request 表 structure 配置的 IF:{ {k}:value } 中 value 不合法,必须是 JSO
Error message
Request 表 structure 配置的 IF:{ {k}:value } 中 value 不合法,必须是 JSONRequest {} ! What it means
In the Request table 'structure', an IF condition maps a key to a conditional sub-structure: IF:{ "key": { ...structure to apply when key present...} }. The value of each IF entry must be a JSONRequest object (Map). This IllegalArgumentException fires when the value is a scalar, array, or string instead of a Map — the verifier cannot recursively parse a non-object as a structure template.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java:1325
boolean isElse = StringUtil.isEmpty(k, false); // 其它直接报错,不允许传 StringUtil.isEmpty(k, true) || "ELSE".equals(k);
// String code = preCode + "\n\n" + (StringUtil.isEmpty(v, false) ? k : (isElse ? v : "if (" + k + ") {\n " + v + "\n}"));
String code = preCode + "\n\n" + (isElse ? v : "if (" + k + ") {\n " + v + "\n}");
// ScriptExecutor executor = new JavaScriptExecutor();
// executor.execute(null, real, )
engine.eval(code);
// PARSER_CREATOR.createFunctionParser()
// .setCurrentObject(real)
// .setKey(k)
// .setMethod(method)
// .invoke()
continue;
}
if (v instanceof Map<?, ?> == false) {
throw new IllegalArgumentException("Request 表 structure 配置的 " + IF.name()
+ ":{ " + k + ":value } 中 value 不合法,必须是 JSONRequest {} !");
}
if (nkl.contains(k) || real.get(k) != null) {
real = parse(method, name, (M) v, real, database, datasource, namespace, catalog, schema, idCallback, parser, callback);
}
}
}
}
Log.i(TAG, "parse return real = " + toJSONString(real));
return real;
}
public static ScriptEngine getScriptEngine(String lang) {
if (ENABLE_SCRIPT_FUNCTION == false) {
throw new UnsupportedOperationException("AbstractFunctionParser.ENABLE_SCRIPT_FUNCTION" +
" == false 时不支持执行脚本!如需支持则设置为 true !");View on GitHub (pinned to 5284052872)
Solutions
- Change the IF value to a JSONRequest object containing the keys to merge in when the condition key is present, e.g. "IF":{"userId":{"User":{...}}} (or {} if no extra structure is needed).
- If you intended a value check, use the documented condition/expression mechanism (e.g. "condition": ...) instead of IF with a literal.
- Validate the Request row locally: for each entry k in structure.IF, assert value is a JSON object before deploying.
Example fix
// before
"IF":{"userId":true}
// after
"IF":{"userId":{"User":{"@column":"id,name"}}} Defensive patterns
Strategy: validation
Validate before calling
void validateStructure(JSONObject structure) {
JSONObject iff = structure == null ? null : structure.getJSONObject("IF");
if (iff == null) return;
for (String k : iff.keySet()) {
Object v = iff.get(k);
if (!(v instanceof Map))
throw new IllegalStateException("structure.IF." + k + " must be a JSONRequest object, got " + (v == null ? "null" : v.getClass().getSimpleName()));
}
} Type guard
function isIfValueOk(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); } Prevention
- When editing Request structure JSON, use a schema/lint that enforces every IF entry is an object.
- Keep IF examples from the official docs at hand; IF holds conditional sub-structures, not expected values.
When it happens
Trigger: A Request structure contains e.g. "IF":{"userId": 1} or "IF":{"userId":"@exists"} — any IF entry whose value is not a Map. On the next request using that tag/method, AbstractVerifier.parse reaches the IF branch, finds v instanceof Map == false, and throws before evaluating the condition.
Common situations: Misreading IF as a value-comparison operator (writing the expected value instead of a conditional structure); hand-editing structure JSON and replacing the nested object with a literal; doc/example confusion between IF (conditional structure) and condition keys like 'condition':'userId>0'.
Related errors
- 后端 Request 表中 ALLOW_PARTIAL_UPDATE_FAIL:value 中 {key} 不合法!必须
- 后端 Request 表中 ALLOW_PARTIAL_UPDATE_FAIL:value 中 {key} 对应的 {k
- 后端 Request 表中 ALLOW_PARTIAL_UPDATE_FAIL:value 中 {key} 不合法![]
- 找不到 version: ${version}, method: ${method.name()}, tag: ${ta
- {name}: { IF: value } 中 value 类型错误!只允许 String, JSONRequest!
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/5e4c81fda513cf06.
Report an issue: GitHub.