Skip to content

Instantly share code, notes, and snippets.

View Papashkin's full-sized avatar
👻

Pavel Antoshkin Papashkin

👻
View GitHub Profile
@BramYeh
BramYeh / LowercaseEnumTypeAdapterFactory
Created March 28, 2017 13:11
LowercaseEnumTypeAdapterFactory
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);