google/gson · error · IllegalArgumentException

Class does not implement any supported type adapter class…

Error message

Class ${typeAdapter.getClass().getName()} does not implement any supported type adapter class or interface

What it means

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.

Solutions

  1. Make the object implement one of TypeAdapter, JsonSerializer, JsonDeserializer, or InstanceCreator.
  2. Double-check the class implements the correct Gson interface (com.google.gson.*, not another JSON library).
  3. If you intended to register a factory, use registerTypeAdapterFactory instead.
  4. Ensure you pass an instance, not the Class<?>.

Example fix

// before
class MyDateSupport { String format(Date d){...} }
builder.registerTypeAdapter(Date.class, new MyDateSupport()); // throws

// after
class MyDateSerializer implements JsonSerializer<Date> {
  public JsonElement serialize(Date d, Type t, JsonSerializationContext c) {...}
}
builder.registerTypeAdapter(Date.class, new MyDateSerializer());
Defensive patterns

Strategy: type-guard

Validate before calling

// Ensure the object implements a supported interface before registering
static boolean isSupportedAdapter(Object o) {
  return o instanceof TypeAdapter || o instanceof JsonSerializer
      || o instanceof JsonDeserializer || o instanceof InstanceCreator;
}
if (!isSupportedAdapter(adapter)) {
  throw new IllegalArgumentException("Not a supported adapter: " + adapter.getClass());
}
builder.registerTypeAdapter(type, adapter);

Try / catch

try { builder.registerTypeAdapter(type, adapter); }
catch (IllegalArgumentException e) {
  if (e.getMessage().contains("does not implement any supported type adapter")) {
    // implement the right interface and retry
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of google/gson@310ac341f2 (2026-08-10). Data as JSON: /api/errors/0051725890c60163. Report an issue: GitHub.

Appendix: source

Thrown at gson/src/main/java/com/google/gson/GsonBuilder.java:747

   * TypeAdapter} should be used instead.
   *
   * @param type the type definition for the type adapter being registered
   * @param typeAdapter This object must implement at least one of the {@link TypeAdapter}, {@link
   *     InstanceCreator}, {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.
   * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
   * @throws IllegalArgumentException if the type adapter being registered is for {@code Object}
   *     class or {@link JsonElement} or any of its subclasses
   * @see #registerTypeHierarchyAdapter(Class, Object)
   */
  @CanIgnoreReturnValue
  public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
    Objects.requireNonNull(type);
    Objects.requireNonNull(typeAdapter);
    if (!(typeAdapter instanceof JsonSerializer<?>
        || typeAdapter instanceof JsonDeserializer<?>
        || typeAdapter instanceof InstanceCreator<?>
        || typeAdapter instanceof TypeAdapter<?>)) {
      throw new IllegalArgumentException(
          "Class "
              + typeAdapter.getClass().getName()
              + " does not implement any supported type adapter class or interface");
    }

    if (hasNonOverridableAdapter(type)) {
      throw new IllegalArgumentException("Cannot override built-in adapter for " + type);
    }

    if (typeAdapter instanceof InstanceCreator<?>) {
      instanceCreators.put(type, (InstanceCreator<?>) typeAdapter);
    }
    if (typeAdapter instanceof JsonSerializer<?> || typeAdapter instanceof JsonDeserializer<?>) {
      TypeToken<?> typeToken = TypeToken.get(type);
      factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(typeToken, typeAdapter));
    }
    if (typeAdapter instanceof TypeAdapter<?>) {
      @SuppressWarnings({"unchecked", "rawtypes"})

View on GitHub (pinned to 310ac341f2)