org.ctoolkit.restapi.client.adapter.DateTimeToDateConverter Maven / Gradle / Ivy
package org.ctoolkit.restapi.client.adapter;
import com.google.api.client.util.DateTime;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;
import java.util.Date;
/**
* The bidirectional Google API client {@link DateTime} vs. standard java {@link Date} converter.
* If needed configure your orika mapper:
*
*
* import ma.glasnost.orika.converter.ConverterFactory;
* import ma.glasnost.orika.MapperFactory;
* ..
*
* @Inject
* MapperFactory factory;
*
* ..
* ConverterFactory converterFactory = factory.getConverterFactory();
* converterFactory.registerConverter( new DateTimeToDateConverter() );
*
*
* @author Aurel Medvegy
*/
public class DateTimeToDateConverter
extends BidirectionalConverter
{
@Override
public Date convertTo( DateTime source, Type destinationType, MappingContext context )
{
return new Date( source.getValue() );
}
@Override
public DateTime convertFrom( Date source, Type destinationType, MappingContext context )
{
return new DateTime( source );
}
}