Implemented an URI-to-String converter
[jpa-converters] / src / main / java / de / juplo / jpa / converters / URIConverter.java
1 package de.juplo.jpa.converters;
2
3 import java.net.URI;
4 import javax.persistence.AttributeConverter;
5 import javax.persistence.Converter;
6
7
8 /**
9  * Converts an {@link URI} to its ASCII-representation
10  * @author Kai Moritz
11  */
12 @Converter(autoApply = true)
13 public class URIConverter implements AttributeConverter<URI, String>
14 {
15   @Override
16   public String convertToDatabaseColumn(URI uri)
17   {
18     return uri.toASCIIString();
19   }
20
21   @Override
22   public URI convertToEntityAttribute(String string)
23   {
24     return URI.create(string);
25   }  
26 }