{"record":{"id":"0051725890c60163","repo":"google/gson","slug":"class-typeadapter-getclass-getname-does-not","errorCode":null,"errorMessage":"Class ${typeAdapter.getClass().getName()} does not implement any supported type adapter class or interface","messagePattern":"Class (.+?) does not implement any supported type adapter class or interface","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/GsonBuilder.java","lineNumber":747,"sourceCode":"   * TypeAdapter} should be used instead.\n   *\n   * @param type the type definition for the type adapter being registered\n   * @param typeAdapter This object must implement at least one of the {@link TypeAdapter}, {@link\n   *     InstanceCreator}, {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.\n   * @return a reference to this {@code GsonBuilder} object to fulfill the \"Builder\" pattern\n   * @throws IllegalArgumentException if the type adapter being registered is for {@code Object}\n   *     class or {@link JsonElement} or any of its subclasses\n   * @see #registerTypeHierarchyAdapter(Class, Object)\n   */\n  @CanIgnoreReturnValue\n  public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {\n    Objects.requireNonNull(type);\n    Objects.requireNonNull(typeAdapter);\n    if (!(typeAdapter instanceof JsonSerializer<?>\n        || typeAdapter instanceof JsonDeserializer<?>\n        || typeAdapter instanceof InstanceCreator<?>\n        || typeAdapter instanceof TypeAdapter<?>)) {\n      throw new IllegalArgumentException(\n          \"Class \"\n              + typeAdapter.getClass().getName()\n              + \" does not implement any supported type adapter class or interface\");\n    }\n\n    if (hasNonOverridableAdapter(type)) {\n      throw new IllegalArgumentException(\"Cannot override built-in adapter for \" + type);\n    }\n\n    if (typeAdapter instanceof InstanceCreator<?>) {\n      instanceCreators.put(type, (InstanceCreator<?>) typeAdapter);\n    }\n    if (typeAdapter instanceof JsonSerializer<?> || typeAdapter instanceof JsonDeserializer<?>) {\n      TypeToken<?> typeToken = TypeToken.get(type);\n      factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(typeToken, typeAdapter));\n    }\n    if (typeAdapter instanceof TypeAdapter<?>) {\n      @SuppressWarnings({\"unchecked\", \"rawtypes\"})","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/google/gson/blob/310ac341f2f92a454b229bf21f70d2d18b2b6db7/gson/src/main/java/com/google/gson/GsonBuilder.java#L729-L765","documentation":"Thrown by GsonBuilder.registerTypeAdapter(Type, Object) when the object passed as the adapter does not implement any of the supported interfaces: TypeAdapter, JsonSerializer, JsonDeserializer, or InstanceCreator. Gson refuses to store an object it cannot dispatch on, failing fast at configuration with an IllegalArgumentException naming the offending class.","triggerScenarios":"Passing a plain lambda/POJO that is none of the supported interfaces; passing a JsonSerializer<?> captured as Object without the interface; passing a factory where an adapter is expected; passing a class object instead of an instance; missing 'implements' clause.","commonSituations":"Forgetting to make the adapter implement JsonSerializer/TypeAdapter; passing a Serializer written for a different library; raw-type generics hiding a missing implements; IDE auto-import picking the wrong JsonSerializer.","solutions":["Make the object implement one of TypeAdapter, JsonSerializer, JsonDeserializer, or InstanceCreator.","Double-check the class implements the correct Gson interface (com.google.gson.*, not another JSON library).","If you intended to register a factory, use registerTypeAdapterFactory instead.","Ensure you pass an instance, not the Class<?>."],"exampleFix":"// before\nclass MyDateSupport { String format(Date d){...} }\nbuilder.registerTypeAdapter(Date.class, new MyDateSupport()); // throws\n\n// after\nclass MyDateSerializer implements JsonSerializer<Date> {\n  public JsonElement serialize(Date d, Type t, JsonSerializationContext c) {...}\n}\nbuilder.registerTypeAdapter(Date.class, new MyDateSerializer());","handlingStrategy":"type-guard","validationCode":"// Ensure the object implements a supported interface before registering\nstatic boolean isSupportedAdapter(Object o) {\n  return o instanceof TypeAdapter || o instanceof JsonSerializer\n      || o instanceof JsonDeserializer || o instanceof InstanceCreator;\n}\nif (!isSupportedAdapter(adapter)) {\n  throw new IllegalArgumentException(\"Not a supported adapter: \" + adapter.getClass());\n}\nbuilder.registerTypeAdapter(type, adapter);","typeGuard":null,"tryCatchPattern":"try { builder.registerTypeAdapter(type, adapter); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"does not implement any supported type adapter\")) {\n    // implement the right interface and retry\n  } else throw e;\n}","preventionTips":["Implement at least one of TypeAdapter, JsonSerializer, JsonDeserializer, InstanceCreator.","Confirm the import is com.google.gson.*.","Pass an instance, not a Class or a factory."],"tags":["gson-builder","type-adapter","configuration","registration"],"backgroundTag":null,"analyzedSha":"310ac341f2f92a454b229bf21f70d2d18b2b6db7","analyzedAt":"2026-08-10T02:58:47.455Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}