From: Kai Moritz Date: Mon, 21 Dec 2015 22:45:48 +0000 (+0100) Subject: Implemented a Year-to-Integer converter X-Git-Tag: jpa-converters-1.0.0~20 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=1c32d9ec8c9dd7b65bcfdd89d2b75d16609e299c;p=jpa-converters Implemented a Year-to-Integer converter --- diff --git a/src/main/java/de/juplo/jpa/converters/YearConverter.java b/src/main/java/de/juplo/jpa/converters/YearConverter.java new file mode 100644 index 0000000..59875a6 --- /dev/null +++ b/src/main/java/de/juplo/jpa/converters/YearConverter.java @@ -0,0 +1,26 @@ +package de.juplo.jpa.converters; + +import java.time.Year; +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + + +/** + * Converts a {@link Year} into its {@link Integer} representation. + * @author Kai Moritz + */ +@Converter(autoApply = true) +public class YearConverter implements AttributeConverter +{ + @Override + public Integer convertToDatabaseColumn(Year year) + { + return year.getValue(); + } + + @Override + public Year convertToEntityAttribute(Integer integer) + { + return Year.of(integer); + } +}