{"record":{"id":"86de2ed37c2f9187","repo":"Tencent/APIJSON","slug":"method-name-key-idkey-value-value","errorCode":null,"errorMessage":"{method}请求，{name}/{key} 里面的 {idKey}:value 中value的类型只能是 Long 或 String ！","messagePattern":"(.+?)请求，(.+?)/(.+?) 里面的 (.+?):value 中value的类型只能是 Long 或 String ！","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java","lineNumber":750,"sourceCode":"\t\t});\n\n\t}\n\n\t/**\n\t * @param method\n\t * @param name\n\t * @param key\n\t * @param robj\n\t * @param idKey\n\t * @param atLeastOne 至少有一个不为null\n\t */\n\tprivate static <T, M extends Map<String, Object>, L extends List<Object>> void verifyId(\n\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","sourceCodeStart":732,"sourceCodeEnd":768,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java#L732-L768","documentation":"Thrown by AbstractVerifier.verifyId (APIJSON ORM) when a single-record write request (PUT/DELETE) supplies an id whose runtime type is neither Number nor String. The verifier only accepts numeric Long-style ids or string ids so it can safely generate the WHERE id = ? condition without type ambiguity.","triggerScenarios":"A PUT/DELETE body like {\"User\":{\"id\":true}} or {\"User\":{\"id\":{} }} or {\"User\":{\"id\":[1]}} — i.e. robj.get(idKey) returns a Boolean, Map, or List instead of a Number/String.","commonSituations":"Client serializes a boolean flag or nested object into the id field; frontend sends id as a JSON object after a refactoring; a proxy/gateway rewrites id into an array; using a non-standard idKey whose value is a struct.","solutions":["Change the id value in the request to a Long (e.g. 82001) or a numeric/uuid String (e.g. \"82001\")","If the client DTO serializes id as an object, flatten it to a scalar before sending","Check middleware that may wrap or transform the id field"],"exampleFix":"// before\n{\"User\":{\"id\":{\"value\":82001},\"name\":\"a\"}}\n// after\n{\"User\":{\"id\":82001,\"name\":\"a\"}}","handlingStrategy":"validation","validationCode":"function assertIdType(obj, idKey = 'id') {\n  const v = obj[idKey];\n  if (v != null && typeof v !== 'number' && typeof v !== 'string') {\n    throw new TypeError(`${idKey} must be a number or string, got ${typeof v}`);\n  }\n}","typeGuard":"const isIdValue = (v) => v == null || typeof v === 'number' || typeof v === 'string';","tryCatchPattern":"catch (e) { if (e instanceof IllegalArgumentException && /id.*Long 或 String/.test(e.message)) showFieldError('id'); else throw e; }","preventionTips":["Type the id field as number|string in client models","Run a shared pre-send sanitizer over every write body","Log the offending raw JSON body when this fires to find which field was malformed"],"tags":["apijson","validation","id-type","put-delete"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}