nl.vpro.persistence.InstantToTimestampConverter Maven / Gradle / Ivy
package nl.vpro.persistence;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.sql.Timestamp;
import java.time.Instant;
/**
* @author Michiel Meeuwissen
* @since 0.36
*/
@Converter(autoApply = true)
public class InstantToTimestampConverter implements AttributeConverter {
@Override
public Timestamp convertToDatabaseColumn(Instant instant) {
return instant == null ? null : Timestamp.from(instant);
}
@Override
public Instant convertToEntityAttribute(Timestamp timestamp) {
return timestamp == null ? null : timestamp.toInstant();
}
}