Prevented possible NullPointerException's
[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     if (uri == null)
19       return null;
20     return uri.toASCIIString();
21   }
22
23   @Override
24   public URI convertToEntityAttribute(String string)
25   {
26     if (string == null)
27       return null;
28     return URI.create(string);
29   }  
30 }