This is an automated email from the ASF dual-hosted git repository.
jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/johnzon.git
The following commit(s) were added to refs/heads/master by this push:
new 09d6bf8c feat: Fix Locale adapter using Java 7+ helper method from
Locale
09d6bf8c is described below
commit 09d6bf8cf72a16774de8c876893e0ed2cbaa54cc
Author: Jean-Louis Monteiro <[email protected]>
AuthorDate: Wed Oct 11 15:15:26 2023 +0200
feat: Fix Locale adapter using Java 7+ helper method from Locale
Signed-off-by: Jean-Louis Monteiro <[email protected]>
---
.../johnzon/mapper/converter/LocaleConverter.java | 32 ++--------------------
1 file changed, 2 insertions(+), 30 deletions(-)
diff --git
a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/converter/LocaleConverter.java
b/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/converter/LocaleConverter.java
index 6dd330fa..565a2a42 100644
---
a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/converter/LocaleConverter.java
+++
b/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/converter/LocaleConverter.java
@@ -53,35 +53,7 @@ public class LocaleConverter implements
TypeAwareAdapter<Locale, String> {
if (locale == null) {
return null;
}
- final int len = locale.length();
- if (len != 2 && len != 5 && len < 7) {
- throw new IllegalArgumentException("Invalid locale format: " +
locale);
- }
- final char ch0 = locale.charAt(0);
- final char ch1 = locale.charAt(1);
- if (ch0 < 'a' || ch0 > 'z' || ch1 < 'a' || ch1 > 'z') {
- throw new IllegalArgumentException("Invalid locale format: " +
locale);
- }
- if (len == 2) {
- return new Locale(locale, "");
- }
- if (locale.charAt(2) != '_') {
- throw new IllegalArgumentException("Invalid locale format: " +
locale);
- }
- final char ch3 = locale.charAt(3);
- if (ch3 == '_') {
- return new Locale(locale.substring(0, 2), "", locale.substring(4));
- }
- final char ch4 = locale.charAt(4);
- if (ch3 < 'A' || ch3 > 'Z' || ch4 < 'A' || ch4 > 'Z') {
- throw new IllegalArgumentException("Invalid locale format: " +
locale);
- }
- if (len == 5) {
- return new Locale(locale.substring(0, 2), locale.substring(3, 5));
- }
- if (locale.charAt(5) != '_') {
- throw new IllegalArgumentException("Invalid locale format: " +
locale);
- }
- return new Locale(locale.substring(0, 2), locale.substring(3, 5),
locale.substring(6));
+
+ return Locale.forLanguageTag(locale);
}
}