{"record":{"id":"4333ea72fcd85163","repo":"Tencent/APIJSON","slug":"puts-stringutil-isempty-key-true-clazz-getannot","errorCode":null,"errorMessage":"puts  StringUtil.isEmpty(key, true) clazz.getAnnotation(MethodAccess.class) == null \\n key为空时仅支持 类型被@MethodAccess注解 的value !!! \\n 如果一定要这么用，请对 \" + clazz.getName() + \" 注解！ \\n 如果是类似 key[]:{} 结构的请求，建议用 putsAll(...) ！","messagePattern":"puts  StringUtil\\.isEmpty\\(key, true\\) clazz\\.getAnnotation\\(MethodAccess\\.class\\) == null \\\\n key为空时仅支持 类型被@MethodAccess注解 的value !!! \\\\n 如果一定要这么用，请对 \" \\+ clazz\\.getName\\(\\) \\+ \" 注解！ \\\\n 如果是类似 key\\[\\]:(.+?) 结构的请求，建议用 putsAll\\(\\.\\.\\.\\) ！","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/JSONMap.java","lineNumber":681,"sourceCode":"\t\treturn this;\n\t}\n\t/**put and return this\n\t * @param key\n\t * @param value \n\t * @return this\n\t */\n\tdefault JSONMap<M, L> puts(String key, Object value) {\n\t\tput(key, value);\n\t\treturn this;\n\t}\n\n\t/**put and return value\n\t * @param value  must be annotated by {@link MethodAccess}\n\t */\n\tdefault Object put(Object value) {\n\t\tClass<?> clazz = value.getClass(); //should not return null\n\t\tif (clazz.getAnnotation(MethodAccess.class) == null) {\n\t\t\tthrow new IllegalArgumentException(\"puts  StringUtil.isEmpty(key, true)\" +\n\t\t\t\t\t\" clazz.getAnnotation(MethodAccess.class) == null\" +\n\t\t\t\t\t\" \\n key为空时仅支持 类型被@MethodAccess注解 的value !!!\" +\n\t\t\t\t\t\" \\n 如果一定要这么用，请对 \" + clazz.getName() + \" 注解！\" +\n\t\t\t\t\t\" \\n 如果是类似 key[]:{} 结构的请求，建议用 putsAll(...) ！\");\n\t\t}\n\t\treturn put(clazz.getSimpleName(), value);\n\t}\n\n\t/**puts key-value in object into this\n\t * @param map\n\t * @return this\n\t */\n\tdefault JSONMap<M, L> putsAll(Map<? extends String, ? extends Object> map) {\n\t\tputAll(map);\n\t\treturn this;\n\t}\n\n","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/JSONMap.java#L663-L699","documentation":"JSONMap.put(Object value) is a convenience overload that derives the key from the value's class simple name, but it only accepts classes annotated with @MethodAccess (APIJSON's per-class CRUD permission annotation). If the runtime class lacks the annotation, the library throws IllegalArgumentException listing the class and suggesting puts(key, value) or putsAll(...).","triggerScenarios":"Calling puts(value) or put(value) on a JSONMap/JSONObjectRequest with a POJO whose class is not annotated with @MethodAccess.","commonSituations":"New DTO added to a request without copying the @MethodAccess annotation from existing models; using third-party or java.* classes as values; refactoring renamed the class and the annotation was lost.","solutions":["Annotate the value class with @MethodAccess (e.g. @MethodAccess(GET=true, POST=true)) like other APIJSON models.","Or use the explicit-key overload puts(\"User\", value) which bypasses the annotation check.","For array-style requests key[]:{} use putsAll(...) as the message suggests.","If the class is not under your control, wrap it in your own annotated wrapper class."],"exampleFix":"// before\npublic class User { ... }\nrequest.puts(new User()); // throws\n\n// after\n@MethodAccess(POST = true, GET = true)\npublic class User { ... }\nrequest.puts(new User());","handlingStrategy":"validation","validationCode":"if (value.getClass().getAnnotation(MethodAccess.class) == null) {\n    map.puts(value.getClass().getSimpleName(), value); // explicit key bypasses the check\n}","typeGuard":"public static <T> boolean isMethodAccessAnnotated(Class<T> clazz) {\n    return clazz.getAnnotation(MethodAccess.class) != null;\n}","tryCatchPattern":"try { request.puts(value); } catch (IllegalArgumentException e) { request.puts(value.getClass().getSimpleName(), value); }","preventionTips":["Copy @MethodAccess onto every model used in puts(Object) — treat it as part of the class template.","Prefer puts(key, value) for third-party classes you cannot annotate.","Add a startup check that scans request model packages for missing @MethodAccess."],"tags":["apijson","annotation","methodaccess","request-building"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}