Prevented possible NullPointerException's
[jpa-converters] / src / main / java / de / juplo / jpa / converters / ZoneIdConverter.java
1 package de.juplo.jpa.converters;
2
3 import java.time.ZoneId;
4 import javax.persistence.AttributeConverter;
5 import javax.persistence.Converter;
6
7
8 /**
9  * Converts a {@link ZoneID} to its string-representation as ID.
10  * @author Kai Moritz
11  */
12 @Converter(autoApply = true)
13 public class ZoneIdConverter implements AttributeConverter<ZoneId,String>
14 {
15   @Override
16   public String convertToDatabaseColumn(ZoneId zone)
17   {
18     if (zone == null)
19       return null;
20     return zone.getId();
21   }
22
23   @Override
24   public ZoneId convertToEntityAttribute(String string)
25   {
26     if (string == null)
27       return null;
28     return ZoneId.of(string);
29   }
30 }