Implemented a ZoneID-to-String converter
authorKai Moritz <kai@juplo.de>
Mon, 21 Dec 2015 20:39:19 +0000 (21:39 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 22 Dec 2015 09:54:35 +0000 (10:54 +0100)
src/main/java/de/juplo/jpa/converters/ZoneIdConverter.java [new file with mode: 0644]

diff --git a/src/main/java/de/juplo/jpa/converters/ZoneIdConverter.java b/src/main/java/de/juplo/jpa/converters/ZoneIdConverter.java
new file mode 100644 (file)
index 0000000..57f3ba1
--- /dev/null
@@ -0,0 +1,26 @@
+package de.juplo.jpa.converters;
+
+import java.time.ZoneId;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link ZoneID} to its string-representation as ID.
+ * @author Kai Moritz
+ */
+@Converter(autoApply = true)
+public class ZoneIdConverter implements AttributeConverter<ZoneId,String>
+{
+  @Override
+  public String convertToDatabaseColumn(ZoneId zone)
+  {
+    return zone.getId();
+  }
+
+  @Override
+  public ZoneId convertToEntityAttribute(String string)
+  {
+    return ZoneId.of(string);
+  }
+}