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

com.googlecode.objectify.impl.conv.EnumConverter Maven / Gradle / Ivy

Go to download

*** THIS VERSION UPLOADED FOR USE WITH CEDAR-COMMON, TO AVOID DEPENDENCIES ON GOOGLE CODE-BASED MAVEN REPOSITORIES. *** The simplest convenient interface to the Google App Engine datastore

The newest version!
package com.googlecode.objectify.impl.conv;


/**
 * Knows how to convert Enums 
 */
public class EnumConverter implements Converter
{
	@Override
	public Object forDatastore(Object value, ConverterSaveContext ctx)
	{
		if (value instanceof Enum)
			return ((Enum)value).name();
		else
			return null;
	}

	@Override
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Object forPojo(Object value, Class fieldType, ConverterLoadContext ctx, Object onPojo)
	{
		if (Enum.class.isAssignableFrom(fieldType))
			// Anyone have any idea how to avoid this generics warning?
			return Enum.valueOf((Class)fieldType, value.toString());
		else
			return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy