From c01fc5c9352b34024fd19d296c814051d334a564 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 16 Dec 2011 14:12:34 +0000 Subject: [PATCH] Fix tests broken by r1078. --- .../com/google/gson/internal/bind/TypeAdapters.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java index c90aaa7d..ae97052e 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java +++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java @@ -677,15 +677,20 @@ public final class TypeAdapters { } } - public static final TypeAdapter.Factory ENUM_FACTORY = newEnumTypeHierarchyFactory(Enum.class); + public static final TypeAdapter.Factory ENUM_FACTORY = newEnumTypeHierarchyFactory(); - public static TypeAdapter.Factory newEnumTypeHierarchyFactory(final Class clazz) { + public static TypeAdapter.Factory newEnumTypeHierarchyFactory() { return new TypeAdapter.Factory() { @SuppressWarnings({"rawtypes", "unchecked"}) public TypeAdapter create(Gson gson, TypeToken typeToken) { Class rawType = typeToken.getRawType(); - return clazz.isAssignableFrom(rawType) - ? (TypeAdapter) new EnumTypeAdapter(rawType) : null; + if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) { + return null; + } + if (!rawType.isEnum()) { + rawType = rawType.getSuperclass(); // handle anonymous subclasses + } + return (TypeAdapter) new EnumTypeAdapter(rawType); } }; }