@@ -220,6 +220,13 @@ public static class Std extends FromStringDeserializer<Object>
220
220
public final static int STD_INET_ADDRESS = 11 ;
221
221
public final static int STD_INET_SOCKET_ADDRESS = 12 ;
222
222
public final static int STD_STRING_BUILDER = 13 ;
223
+ /**
224
+ * If you are using java's {@linkplain Locale#toString()} serialize Locale
225
+ * (split language, country and variant with '_')<br>
226
+ * You can force jackson deserialize String to Locale with java Locale style.<br>
227
+ * config: {@linkplain System#setProperty(String, String) System.setProperty("jackson.std.locale.de.java", "not empty")}
228
+ */
229
+ public final static String STD_LOCALE_DE_JAVA = "jackson.std.locale.de.java" ;
223
230
224
231
protected final int _kind ;
225
232
@@ -255,6 +262,10 @@ protected Object _deserialize(String value, DeserializationContext ctxt) throws
255
262
return Pattern .compile (value );
256
263
case STD_LOCALE :
257
264
{
265
+ if (!System .getProperty (STD_LOCALE_DE_JAVA , "" ).isEmpty ()) {
266
+ return deJavaLocale (value );
267
+ }
268
+
258
269
int ix = _firstHyphenOrUnderscore (value );
259
270
if (ix < 0 ) { // single argument
260
271
return new Locale (value );
@@ -330,5 +341,30 @@ protected int _firstHyphenOrUnderscore(String str)
330
341
}
331
342
return -1 ;
332
343
}
344
+
345
+ /** see {@link Locale#toString()}, but ignore extends */
346
+ private Locale deJavaLocale (String value ) {
347
+ if (value .isEmpty ()) {
348
+ return new Locale ("" );
349
+ }
350
+
351
+ int extStart = value .indexOf ("_#" );
352
+ if (extStart != -1 ) value = value .substring (0 , extStart );
353
+
354
+ String language = value , country = "" , variant = "" ;
355
+ int pos1 = value .indexOf ('_' );
356
+ if (pos1 != -1 ) {
357
+ language = value .substring (0 , pos1 ++);
358
+
359
+ int pos2 = value .indexOf ('_' , pos1 );
360
+ if (pos2 == -1 ) {
361
+ country = value .substring (pos1 );
362
+ } else {
363
+ country = value .substring (pos1 , pos2 );
364
+ variant = value .substring (pos2 + 1 );
365
+ }
366
+ }
367
+ return new Locale (language , country , variant );
368
+ }
333
369
}
334
370
}
0 commit comments