This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LowercaseEnumTypeAdapterFactory implements TypeAdapterFactory { | |
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { | |
Class<T> rawType = (Class<T>) type.getRawType(); | |
if (!rawType.isEnum()) { | |
return null; | |
} | |
final Map<String, T> lowercaseToConstant = new HashMap<String, T>(); | |
for (T constant : rawType.getEnumConstants()) { | |
lowercaseToConstant.put(toLowercase(constant), constant); |