{"record":{"id":"962bf65f489279c8","repo":"google/gson","slug":"serializedname-on-methoddescription-is-not-sup","errorCode":null,"errorMessage":"@SerializedName on ${methodDescription} is not supported","messagePattern":"@SerializedName on (.+?) is not supported","errorType":"exception","errorClass":"JsonIOException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java","lineNumber":383,"sourceCode":"          // GsonBuilder.excludeFieldsWithModifiers can overwrite this.\n          if (Modifier.isStatic(field.getModifiers())) {\n            deserialize = false;\n          } else {\n            accessor = ReflectionHelper.getAccessor(raw, field);\n            // If blockInaccessible, skip and perform access check later\n            if (!blockInaccessible) {\n              ReflectionHelper.makeAccessible(accessor);\n            }\n\n            // @SerializedName can be placed on accessor method, but it is not supported there\n            // If field and method have annotation it is not easily possible to determine if\n            // accessor method is implicit and has inherited annotation, or if it is explicitly\n            // declared with custom annotation\n            if (accessor.getAnnotation(SerializedName.class) != null\n                && field.getAnnotation(SerializedName.class) == null) {\n              String methodDescription =\n                  ReflectionHelper.getAccessibleObjectDescription(accessor, false);\n              throw new JsonIOException(\n                  \"@SerializedName on \" + methodDescription + \" is not supported\");\n            }\n          }\n        }\n\n        // If blockInaccessible, skip and perform access check later\n        // For Records if the accessor method is used the field does not have to be made accessible\n        if (!blockInaccessible && accessor == null) {\n          ReflectionHelper.makeAccessible(field);\n        }\n\n        Type fieldType = GsonTypes.resolve(type.getType(), raw, field.getGenericType());\n        List<String> fieldNames = getFieldNames(field);\n        String serializedName = fieldNames.get(0);\n        BoundField boundField =\n            createBoundField(\n                context,\n                field,","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/google/gson/blob/310ac341f2f92a454b229bf21f70d2d18b2b6db7/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java#L365-L401","documentation":"For records, Gson resolves the JSON name from the record component/field, never from the accessor method. If it detects @SerializedName on the accessor method while the underlying field lacks it, it throws JsonIOException during adapter construction because the annotation would be silently ignored.","triggerScenarios":"Explicitly declaring a record accessor method and annotating it with @SerializedName, e.g. record Item(int id){ @SerializedName(\"x\") @Override public int id(){...} }.","commonSituations":"Migrating a class with annotated getters to a record; IDE auto-generating accessor methods that carry annotations; misunderstanding where Gson reads record annotations.","solutions":["Move @SerializedName from the accessor method to the record component declaration","Remove the @SerializedName from the accessor method and use the component-level annotation or default naming"],"exampleFix":"// before\nrecord Item(int id) {\n    @SerializedName(\"identifier\")\n    @Override public int id() { return id; } // throws\n}\n\n// after\nrecord Item(@SerializedName(\"identifier\") int id) {}","handlingStrategy":"validation","validationCode":"// At startup, validate that no record accessor carries @SerializedName\nfor (Method m : recordType.getDeclaredMethods()) {\n    if (m.isAnnotationPresent(SerializedName.class)) {\n        throw new IllegalStateException(\"@SerializedName must be on the record component, not accessor: \" + m);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Place @SerializedName on the record component, never on the accessor method","Build Gson at startup to catch this error immediately","Review IDE-generated accessor methods for stray annotations"],"tags":["record","annotation","serializedname","configuration"],"backgroundTag":null,"analyzedSha":"310ac341f2f92a454b229bf21f70d2d18b2b6db7","analyzedAt":"2026-08-10T02:58:47.455Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}