Fix tests broken by r1078.
This commit is contained in:
parent
8fcbd57e59
commit
c01fc5c935
@ -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 <TT> TypeAdapter.Factory newEnumTypeHierarchyFactory(final Class<TT> clazz) {
|
public static <TT> TypeAdapter.Factory newEnumTypeHierarchyFactory() {
|
||||||
return new TypeAdapter.Factory() {
|
return new TypeAdapter.Factory() {
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
|
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
|
||||||
Class<? super T> rawType = typeToken.getRawType();
|
Class<? super T> rawType = typeToken.getRawType();
|
||||||
return clazz.isAssignableFrom(rawType)
|
if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) {
|
||||||
? (TypeAdapter<T>) new EnumTypeAdapter(rawType) : null;
|
return null;
|
||||||
|
}
|
||||||
|
if (!rawType.isEnum()) {
|
||||||
|
rawType = rawType.getSuperclass(); // handle anonymous subclasses
|
||||||
|
}
|
||||||
|
return (TypeAdapter<T>) new EnumTypeAdapter(rawType);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user