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

com.googlecode.objectify.impl.conv.joda.LocalDateConverter 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.joda;

import org.joda.time.LocalDate;

import com.googlecode.objectify.impl.conv.Converter;
import com.googlecode.objectify.impl.conv.ConverterLoadContext;
import com.googlecode.objectify.impl.conv.ConverterSaveContext;


/**
 * Stores LocalDate as a String in ISO format:  yyyy-MM-dd 
 */
public class LocalDateConverter implements Converter
{
	@Override
	public Object forDatastore(Object value, ConverterSaveContext ctx)
	{
		if (value instanceof LocalDate)
			return ((LocalDate) value).toString();
		else
			return null;
	}

	@Override
	public Object forPojo(Object value, Class fieldType, ConverterLoadContext ctx, Object onPojo)
	{
		if (value instanceof String && LocalDate.class.isAssignableFrom(fieldType))
			return new LocalDate(value);
		else
			return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy