From: Kai Moritz Date: Mon, 21 Dec 2015 23:19:45 +0000 (+0100) Subject: Implemented a Locale-to-String converter X-Git-Tag: jpa-converters-1.0.0~17 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=7a11c7d53d9546aa639a2e960811e321805ec643;p=jpa-converters Implemented a Locale-to-String converter --- diff --git a/src/main/java/de/juplo/jpa/converters/LocaleConverter.java b/src/main/java/de/juplo/jpa/converters/LocaleConverter.java new file mode 100644 index 0000000..da84d15 --- /dev/null +++ b/src/main/java/de/juplo/jpa/converters/LocaleConverter.java @@ -0,0 +1,27 @@ +package de.juplo.jpa.converters; + +import java.util.Locale; +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + + +/** + * Converts a {@link Locale} into its {@link String} representation as a + * well-formed IETF BCP 47 language tag. + * @author Kai Moritz + */ +@Converter(autoApply = true) +public class LocaleConverter implements AttributeConverter +{ + @Override + public String convertToDatabaseColumn(Locale locale) + { + return locale.toLanguageTag(); + } + + @Override + public Locale convertToEntityAttribute(String string) + { + return Locale.forLanguageTag(string); + } +}