Implemented an URI-to-String converter
authorKai Moritz <kai@juplo.de>
Mon, 21 Dec 2015 19:54:21 +0000 (20:54 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 21 Dec 2015 19:54:21 +0000 (20:54 +0100)
src/main/java/de/juplo/jpa/converters/URIConverter.java [new file with mode: 0644]

diff --git a/src/main/java/de/juplo/jpa/converters/URIConverter.java b/src/main/java/de/juplo/jpa/converters/URIConverter.java
new file mode 100644 (file)
index 0000000..2ce54a6
--- /dev/null
@@ -0,0 +1,26 @@
+package de.juplo.jpa.converters;
+
+import java.net.URI;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts an {@link URI} to its ASCII-representation
+ * @author Kai Moritz
+ */
+@Converter(autoApply = true)
+public class URIConverter implements AttributeConverter<URI, String>
+{
+  @Override
+  public String convertToDatabaseColumn(URI uri)
+  {
+    return uri.toASCIIString();
+  }
+
+  @Override
+  public URI convertToEntityAttribute(String string)
+  {
+    return URI.create(string);
+  }  
+}