public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)
  {
    Class rawType = type.getRawType();
    if (!rawType.isEnum()) {
      return null;
    }

    final Map lowercaseToConstant = new HashMap();
    for (Object constant : rawType.getEnumConstants()) {
      lowercaseToConstant.put(toLowercase(constant), constant);
    }

    return new TypeAdapter() {
      public void write(JsonWriter out, Object value) throws IOException {
        if (value == null)
          out.nullValue();
        else
          out.value(LowerCaseEnumTypeAdapterFactory.this.toLowercase(value));
      }

      public T read(JsonReader reader) throws IOException
      {
        if (reader.peek() == JsonToken.NULL) {
          reader.nextNull();
          return null;
        }
        return (T) lowercaseToConstant.get(reader.nextString());
      }
    };
  }