nl.vpro.persistence.LocalDateToDateConverter Maven / Gradle / Ivy
package nl.vpro.persistence;
import java.sql.Date;
import java.time.LocalDate;
import java.time.ZoneId;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
/**
* @author Michiel Meeuwissen
* @since 0.36
*/
@Converter
public class LocalDateToDateConverter implements AttributeConverter {
public static final ZoneId ZONE_ID = ZoneId.of("Europe/Amsterdam");
@Override
public Date convertToDatabaseColumn(LocalDate localDate) {
return localDate == null ? null : Date.valueOf(localDate);
}
@Override
public LocalDate convertToEntityAttribute(Date date) {
return date == null ? null : date.toLocalDate();
}
}