{"record":{"id":"5e4c81fda513cf06","repo":"Tencent/APIJSON","slug":"request-structure-if-k-value-value","errorCode":null,"errorMessage":"Request 表 structure 配置的 IF:{ {k}:value } 中 value 不合法，必须是 JSONRequest {} ！","messagePattern":"Request 表 structure 配置的 IF:(.+?):value \\} 中 value 不合法，必须是 JSONRequest (.+?) ！","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java","lineNumber":1325,"sourceCode":"\t\t\t\t\t\tboolean isElse = StringUtil.isEmpty(k, false); // 其它直接报错，不允许传 StringUtil.isEmpty(k, true) || \"ELSE\".equals(k);\n//\t\t\t\t\t\tString code = preCode + \"\\n\\n\" + (StringUtil.isEmpty(v, false) ? k : (isElse ? v : \"if (\" + k + \") {\\n  \" + v + \"\\n}\"));\n\t\t\t\t\t\tString code = preCode + \"\\n\\n\" + (isElse ? v : \"if (\" + k + \") {\\n  \" + v + \"\\n}\");\n\n//\t\t\t\t\t\tScriptExecutor executor = new JavaScriptExecutor();\n//\t\t\t\t\t\texecutor.execute(null, real, )\n\n\t\t\t\t\t\tengine.eval(code);\n\n//\t\t\t\t\t\tPARSER_CREATOR.createFunctionParser()\n//\t\t\t\t\t\t\t\t.setCurrentObject(real)\n//\t\t\t\t\t\t\t\t.setKey(k)\n//\t\t\t\t\t\t\t\t.setMethod(method)\n//\t\t\t\t\t\t\t\t.invoke()\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (v instanceof Map<?, ?> == false) {\n\t\t\t\t\t\tthrow new IllegalArgumentException(\"Request 表 structure 配置的 \" + IF.name()\n\t\t\t\t\t\t\t\t+ \":{ \" + k + \":value } 中 value 不合法，必须是 JSONRequest {} ！\");\n\t\t\t\t\t}\n\n\t\t\t\t\tif (nkl.contains(k) || real.get(k) != null) {\n\t\t\t\t\t\treal = parse(method, name, (M) v, real, database, datasource, namespace, catalog, schema, idCallback, parser, callback);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tLog.i(TAG, \"parse  return real = \" + toJSONString(real));\n\t\treturn real;\n\t}\n\n\tpublic static ScriptEngine getScriptEngine(String lang) {\n\t\tif (ENABLE_SCRIPT_FUNCTION == false) {\n\t\t\tthrow new UnsupportedOperationException(\"AbstractFunctionParser.ENABLE_SCRIPT_FUNCTION\" +\n\t\t\t\t\t\" == false 时不支持执行脚本！如需支持则设置为 true ！\");","sourceCodeStart":1307,"sourceCodeEnd":1343,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java#L1307-L1343","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","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."],"exampleFix":"// before\n\"IF\":{\"userId\":true}\n// after\n\"IF\":{\"userId\":{\"User\":{\"@column\":\"id,name\"}}}","handlingStrategy":"validation","validationCode":"void validateStructure(JSONObject structure) {\n  JSONObject iff = structure == null ? null : structure.getJSONObject(\"IF\");\n  if (iff == null) return;\n  for (String k : iff.keySet()) {\n    Object v = iff.get(k);\n    if (!(v instanceof Map))\n      throw new IllegalStateException(\"structure.IF.\" + k + \" must be a JSONRequest object, got \" + (v == null ? \"null\" : v.getClass().getSimpleName()));\n  }\n}","typeGuard":"function isIfValueOk(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }","tryCatchPattern":null,"preventionTips":["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."],"tags":["apijson","server-config","request-table","structure-config"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}