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> stringToConstant = new HashMap<String, T>();
			for (T constant : rawType.getEnumConstants()) {
				stringToConstant.put(constant.toString(), constant);
			}

			return new TypeAdapter<T>() {
				public void write(JsonWriter out, T value) throws IOException {
					if (value == null) {
						out.nullValue();
					} else {
						out.value(value.toString());
					}
				}

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