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

xyz.morphia.converters.TimestampConverter Maven / Gradle / Ivy

The newest version!
package xyz.morphia.converters;


import xyz.morphia.mapping.MappedField;

import java.sql.Timestamp;
import java.util.Date;


/**
 * @author scotthernandez
 */
public class TimestampConverter extends DateConverter {

    /**
     * Creates the Converter.
     */
    public TimestampConverter() {
        super(Timestamp.class);
    }

    @Override
    public Object decode(final Class targetClass, final Object val, final MappedField optionalExtraInfo) {
        final Date d = (Date) super.decode(targetClass, val, optionalExtraInfo);
        return new Timestamp(d.getTime());
    }

    @Override
    public Object encode(final Object val, final MappedField optionalExtraInfo) {
        if (val == null) {
            return null;
        }
        return new Date(((Timestamp) val).getTime());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy