From: Kai Moritz Date: Mon, 21 Dec 2015 19:54:21 +0000 (+0100) Subject: Implemented an URI-to-String converter X-Git-Tag: jpa-converters-1.0.0~31 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=d0cd441ecbafc565a18f8194523598244da9abbe;p=jpa-converters Implemented an URI-to-String converter --- 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); + } +}