From 7a11c7d53d9546aa639a2e960811e321805ec643 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 22 Dec 2015 00:19:45 +0100 Subject: [PATCH] Implemented a Locale-to-String converter --- .../juplo/jpa/converters/LocaleConverter.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/de/juplo/jpa/converters/LocaleConverter.java 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); + } +} -- 2.20.1