com.googlecode.objectify.stringifier.EnumStringifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectify Show documentation
Show all versions of objectify Show documentation
The simplest convenient interface to the Google App Engine datastore
package com.googlecode.objectify.stringifier;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.repackaged.gentyref.GenericTypeReflector;
import java.lang.reflect.Type;
/**
* Converts Enums back and forth with their string representation
*
* @author Jeff Schnitzer
*/
public class EnumStringifier implements Stringifier, InitializeStringifier
{
private Class enumClass;
@Override
public void init(ObjectifyFactory fact, Type keyType) {
enumClass = (Class)GenericTypeReflector.erase(keyType);
assert Enum.class.isAssignableFrom(enumClass);
}
@Override
public String toString(E obj) {
return obj.name();
}
@Override
public E fromString(String str) {
return (E)Enum.valueOf(enumClass, str);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy