{"record":{"id":"45e3e6e730ff30b4","repo":"Tencent/APIJSON","slug":"id-long-string","errorCode":null,"errorMessage":"{}.id 类型错误，类型必须是 Long/String！","messagePattern":"(.+?)\\.id 类型错误，类型必须是 Long/String！","errorType":"validation","errorClass":"UnsupportedDataTypeException","httpStatus":400,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java","lineNumber":406,"sourceCode":"\t\t\t\tfor (Object id : requestIdArray) {\n\t\t\t\t\tif (id == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (id instanceof Number) { // 不能准确地判断 Long，可能是 Integer\n\t\t\t\t\t\tif (((Number) id).longValue() <= 0 || list.contains(Long.valueOf(\"\" + id)) == false) { // Integer等转为 Long 才能正确判断，强转崩溃\n\t\t\t\t\t\t\tthrow new IllegalAccessException(visitorIdKey + \" = \" + id + \" 的 \" + table\n\t\t\t\t\t\t\t\t\t+ \" 不允许 \" + role + \" 用户的 \" + method.name() + \" 请求！\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (id instanceof String) {\n\t\t\t\t\t\tif (StringUtil.isEmpty(id) || list.contains(id) == false) {\n\t\t\t\t\t\t\tthrow new IllegalAccessException(visitorIdKey + \" = \" + id + \" 的 \" + table\n\t\t\t\t\t\t\t\t\t+ \" 不允许 \" + role + \" 用户的 \" + method.name() + \" 请求！\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new UnsupportedDataTypeException(table + \".id 类型错误，类型必须是 Long/String！\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase OWNER:\n\t\t\tif (config.getMethod() == POST) {\n\t\t\t\tList<String> c = config.getColumn();\n\t\t\t\tList<List<Object>> ovs = config.getValues();\n\t\t\t\tif ( (c == null || c.isEmpty()) || (ovs == null || ovs.isEmpty()) ) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"POST 请求必须在Table内设置要保存的 key:value ！\");\n\t\t\t\t}\n\n\t\t\t\tint index = c.indexOf(visitorIdKey);\n\t\t\t\tif (index >= 0) {\n\t\t\t\t\tObject oid;\n\t\t\t\t\tfor (List<Object> ovl : ovs) {\n\t\t\t\t\t\toid = ovl == null || index >= ovl.size() ? null : ovl.get(index);\n\t\t\t\t\t\tif (oid == null || StringUtil.get(oid).equals(\"\" + visitorId) == false) {","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java#L388-L424","documentation":"In the CONTACT-role id loop, a supplied id must be a Number or a String; anything else (JSONObject, Boolean, null-ish nested structure, List) throws UnsupportedDataTypeException with the message '<table>.id 类型错误，类型必须是 Long/String！'. Note ids that are literally null are skipped by the continue above — the error is strictly about wrong JSON types.","triggerScenarios":"A CONTACT-role request passes an object or array as the id condition value, e.g. \"userId\": {\"$regex\":\"...\"} or \"userId\": [1,2] directly under the visitor id key, or a boolean; the else branch of the instanceof chain fires.","commonSituations":"Client builds dynamic where-values and accidentally nests an object where a scalar belongs; APIJSON operators (key{}, key$) placed under the plain key name; hand-crafted JSON tests using wrong literal types.","solutions":["Change the request so the visitor id key holds a scalar Long or String value (or an array via the documented key{} form).","If a range/match expression is needed, use APIJSON's operator keys (e.g. userId{}) instead of overloading the plain key.","Add client-side schema validation that the id field is number|string before sending."],"exampleFix":"// before\n{ \"User\": { \"userId\": { \"$regex\": \"^12\" }, \"role\": \"CONTACT\" } }\n\n// after\n{ \"User\": { \"userId\": 123, \"role\": \"CONTACT\" } }","handlingStrategy":"type-guard","validationCode":"if (!(idValue instanceof Number) && !(idValue instanceof String)) {\n    clientError(\"id must be Long or String, got \" + idValue.getClass().getSimpleName());\n}","typeGuard":"boolean isScalarId(Object v) { return v == null || v instanceof Number || v instanceof String; }","tryCatchPattern":"catch (UnsupportedDataTypeException e) { 400 bad request; echo the expected types; no retry.","preventionTips":["Type-check request builders: id fields accept number|string only, reject objects/arrays at the client edge.","Use APIJSON operator keys (key{}, key$) for structured conditions instead of nesting objects under plain keys."],"tags":["apijson","validation","type-error","request-contract"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}