{"record":{"id":"f23285733535e94d","repo":"Tencent/APIJSON","slug":"method-name-key-idinkey-value-value","errorCode":null,"errorMessage":"{method}请求，{name}/{key} 里面的 {idInKey}:value 中value的类型只能是 [Long] ！","messagePattern":"(.+?)请求，(.+?)/(.+?) 里面的 (.+?):value 中value的类型只能是 \\[Long\\] ！","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java","lineNumber":763,"sourceCode":"\t\t\t@NotNull String method, @NotNull String name, @NotNull String key\n\t\t\t, @NotNull M robj, @NotNull String idKey, final int maxUpdateCount, boolean atLeastOne) throws Exception {\n\t\t//单个修改或删除\n\t\tObject id = robj.get(idKey); //如果必须传 id ，可在Request表中配置NECESSARY\n\t\tif (id != null && id instanceof Number == false && id instanceof String == false) {\n\t\t\tthrow new IllegalArgumentException(method + \"请求，\" + name + \"/\" + key\n\t\t\t\t\t+ \" 里面的 \" + idKey + \":value 中value的类型只能是 Long 或 String ！\");\n\t\t}\n\n\n\t\t//批量修改或删除\n\t\tString idInKey = idKey + \"{}\";\n\t\t// id引用, 格式: \"id{}@\": \"sql\"\n\t\tString idRefInKey = getString(robj, idKey + \"{}@\");\n\t\tL idIn = null;\n\t\ttry {\n\t\t\tidIn = get(robj, idInKey); //如果必须传 id{} ，可在Request表中配置NECESSARY\n\t\t} catch (Exception e) {\n\t\t\tthrow new IllegalArgumentException(method + \"请求，\" + name + \"/\" + key\n\t\t\t\t\t+ \" 里面的 \" + idInKey + \":value 中value的类型只能是 [Long] ！\");\n\t\t}\n\t\tif (idIn == null) {\n\t\t\tif (atLeastOne && id == null && idRefInKey == null) {\n\t\t\t\tthrow new IllegalArgumentException(method + \"请求，\" + name + \"/\" + key\n\t\t\t\t\t\t+ \" 里面 \" + idKey + \",\" + idInKey  + \",\" + (idKey + \"{}@\") + \" 至少传其中一个！\");\n\t\t\t}\n\t\t} else {\n\t\t\tif (idIn.size() > maxUpdateCount) { //不允许一次操作 maxUpdateCount 条以上记录\n\t\t\t\tthrow new IllegalArgumentException(method + \"请求，\" + name + \"/\" + key\n\t\t\t\t\t\t+ \" 里面的 \" + idInKey + \":[] 中[]的长度不能超过 \" + maxUpdateCount + \" ！\");\n\t\t\t}\n\t\t\t//解决 id{}: [\"1' OR 1='1'))--\"] 绕过id{}限制\n\t\t\t//new ArrayList<Long>(idIn) 不能检查类型，Java泛型擦除问题，居然能把 [\"a\"] 赋值进去还不报错\n\t\t\tfor (int i = 0; i < idIn.size(); i++) {\n\t\t\t\tObject o = idIn.get(i);\n\t\t\t\tif (o == null) {\n\t\t\t\t\tthrow new IllegalArgumentException(method + \"请求，\" + name + \"/\" + key","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java#L745-L781","documentation":"Thrown by verifyId when the batch key id{} exists but its value cannot be read as a List — get(robj, \"id{}\") threw internally. APIJSON requires id{} to be a JSON array of ids for batch UPDATE/DELETE so it can build an IN (...) clause.","triggerScenarios":"PUT/DELETE with {\"User\":{\"id{}\": \"1,2,3\"}} (string instead of array) or {\"User\":{\"id{}\": 12}} (scalar) or {\"User\":{\"id{}\": {\"1\":2}}} (object).","commonSituations":"Client joins ids into a comma-separated string; older client sent a single id to the batch key; a form encoder turned the array into a string before reaching the server.","solutions":["Send id{} as a JSON array: {\"User\":{\"id{}\":[1,2,3]}}","If you only target one record, use the plain id key instead of id{}","Verify no middleware stringifies array body values"],"exampleFix":"// before\n{\"User\":{\"id{}\":\"1,2,3\",\"name\":\"a\"}}\n// after\n{\"User\":{\"id{}\":[1,2,3],\"name\":\"a\"}}","handlingStrategy":"validation","validationCode":"function assertIdInArray(obj, idKey = 'id') {\n  const v = obj[idKey + '{}'];\n  if (v != null && !Array.isArray(v)) throw new TypeError(idKey + '{} must be an array');\n}","typeGuard":"const isIdIn = (obj, idKey = 'id') => { const v = obj[idKey + '{}']; return v == null || Array.isArray(v); };","tryCatchPattern":"catch (e) { if (/id\\{}.*\\[Long\\]/.test(e.message)) convertToListOrRetryWithArray(); else throw e; }","preventionTips":["Never join ids into a comma string; keep them in a JSON array","Send bodies with Content-Type: application/json so arrays survive transport"],"tags":["apijson","validation","batch","id-in"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}