All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.objectify.stringifier.EnumStringifier Maven / Gradle / Ivy

There is a newer version: 6.1.2
Show newest version
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