From d0cd441ecbafc565a18f8194523598244da9abbe Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 21 Dec 2015 20:54:21 +0100 Subject: [PATCH] Implemented an URI-to-String converter --- .../de/juplo/jpa/converters/URIConverter.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/de/juplo/jpa/converters/URIConverter.java 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 index 0000000..2ce54a6 --- /dev/null +++ b/src/main/java/de/juplo/jpa/converters/URIConverter.java @@ -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 +{ + @Override + public String convertToDatabaseColumn(URI uri) + { + return uri.toASCIIString(); + } + + @Override + public URI convertToEntityAttribute(String string) + { + return URI.create(string); + } +} -- 2.20.1