{"record":{"id":"7e64e076180535fa","repo":"Tencent/APIJSON","slug":"post-table-key-value-7e64e0","errorCode":null,"errorMessage":"POST 请求必须在Table内设置要保存的 key:value ！","messagePattern":"POST 请求必须在Table内设置要保存的 key:value ！","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java","lineNumber":416,"sourceCode":"\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) {\n\t\t\t\t\t\t\tthrow new IllegalAccessException(visitorIdKey + \" = \" + oid + \" 的 \" + 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}\n\t\t\t\telse {\n\t\t\t\t\tList<String> nc = new ArrayList<>(c);\n\t\t\t\t\tnc.add(visitorIdKey);\n\t\t\t\t\tconfig.setColumn(nc);\n","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java#L398-L434","documentation":"For the OWNER role on a POST, verifyRole() reads config.getColumn() and config.getValues() to inject the visitor id; if either the column list or the values list is null/empty, IllegalArgumentException states that POST must set key:value inside the Table object. A POST without content cannot be ownership-stamped, so it is rejected before reaching the DB.","triggerScenarios":"A POST request whose table object is empty ({}), or contains only non-column operators (e.g. only \"@role\" or conditions), so SQLConfig ends up with null/empty columns or values while the role is OWNER.","commonSituations":"Client builds POST body from a form that was fully optional and submitted empty; refactoring that moved the key:value payload outside the table object (sibling instead of inside); testing POST with a stub object; keys filtered out by request-format validation leaving an empty object.","solutions":["Put the data to insert inside the table object of the POST request (e.g. {\"User\": {\"name\":\"x\", \"sex\":1}}), not as a sibling or in a wrapper.","Make required fields required in the client form so an empty POST cannot be serialized.","If the intent was a query, use GET instead of POST."],"exampleFix":"// before\n{ \"@role\": \"OWNER\", \"User\": {} }\n\n// after\n{ \"User\": { \"name\": \"apijson\", \"sex\": 1 } }","handlingStrategy":"validation","validationCode":"if (\"POST\".equals(method) && (columns == null || columns.isEmpty() || values == null || values.isEmpty())) {\n    clientError(\"POST requires key:value inside the table object\");\n}","typeGuard":"boolean isNonEmptyPost(Map<String,Object> tableObj) { return tableObj != null && !tableObj.isEmpty(); }","tryCatchPattern":"catch (IllegalArgumentException e) when message contains \"POST 请求必须\" -> 400; require the user to fill at least one field.","preventionTips":["Disable submit until the POST payload has at least one column.","Keep insert data inside the table object, never as siblings."],"tags":["apijson","validation","post","owner-role"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}