@@ -282,6 +282,8 @@ public static class Std extends FromStringDeserializer<Object>
282
282
// No longer implemented here since 2.12
283
283
// public final static int STD_STRING_BUILDER = 13;
284
284
285
+ protected final static String LOCALE_EXT_MARKER = "_#" ;
286
+
285
287
protected final int _kind ;
286
288
287
289
protected Std (Class <?> valueType , int kind ) {
@@ -315,25 +317,7 @@ protected Object _deserialize(String value, DeserializationContext ctxt) throws
315
317
// will throw IAE (or its subclass) if malformed
316
318
return Pattern .compile (value );
317
319
case STD_LOCALE :
318
- {
319
- int ix = _firstHyphenOrUnderscore (value );
320
- if (ix < 0 ) { // single argument
321
- return new Locale (value );
322
- }
323
- String first = value .substring (0 , ix );
324
- value = value .substring (ix +1 );
325
- ix = _firstHyphenOrUnderscore (value );
326
- if (ix < 0 ) { // two pieces
327
- return new Locale (first , value );
328
- }
329
- String second = value .substring (0 , ix );
330
- if (!_isScriptOrExtensionPresent (value )) {
331
- return new Locale (first , second , value .substring (ix +1 ));
332
- } else {
333
- // Issue #3259: Support for BCP 47 java.util.Locale Serialization / De-serialization
334
- return _deSerializeBCP47Locale (value , ix , first , second );
335
- }
336
- }
320
+ return _deserializeLocale (value , ctxt );
337
321
case STD_CHARSET :
338
322
return Charset .forName (value );
339
323
case STD_TIME_ZONE :
@@ -402,17 +386,41 @@ protected int _firstHyphenOrUnderscore(String str)
402
386
return -1 ;
403
387
}
404
388
389
+ private Locale _deserializeLocale (String value , DeserializationContext ctxt )
390
+ throws IOException
391
+ {
392
+ int ix = _firstHyphenOrUnderscore (value );
393
+ if (ix < 0 ) { // single argument
394
+ return new Locale (value );
395
+ }
396
+ String first = value .substring (0 , ix );
397
+ value = value .substring (ix +1 );
398
+ ix = _firstHyphenOrUnderscore (value );
399
+ if (ix < 0 ) { // two pieces
400
+ return new Locale (first , value );
401
+ }
402
+ String second = value .substring (0 , ix );
403
+ if (!_isScriptOrExtensionPresent (value )) {
404
+ return new Locale (first , second , value .substring (ix +1 ));
405
+ }
406
+ // Issue #3259: Support for BCP 47 java.util.Locale Serialization / De-serialization
407
+ return _deSerializeBCP47Locale (value , ix , first , second );
408
+ }
409
+
410
+ private boolean _isScriptOrExtensionPresent (String value ) {
411
+ return value .contains (LOCALE_EXT_MARKER );
412
+ }
413
+
405
414
private Locale _deSerializeBCP47Locale (String value , int ix , String first , String second ) {
406
415
String third = "" ;
407
416
try {
408
417
int scriptExpIx = value .indexOf ("_#" );
409
- /*
410
- * Below condition checks if variant value is present to handle empty variant values such as
411
- * en__#Latn_x-ext
412
- * _US_#Latn
413
- */
414
- if (scriptExpIx > 0 && scriptExpIx > ix )
418
+ // Below condition checks if variant value is present to handle empty variant values such as
419
+ // en__#Latn_x-ext
420
+ // _US_#Latn
421
+ if (scriptExpIx > 0 && scriptExpIx > ix ) {
415
422
third = value .substring (ix + 1 , scriptExpIx );
423
+ }
416
424
value = value .substring (scriptExpIx + 2 );
417
425
418
426
if (value .indexOf ('_' ) < 0 && value .indexOf ('-' ) < 0 ) {
@@ -436,10 +444,6 @@ private Locale _deSerializeBCP47Locale(String value, int ix, String first, Strin
436
444
return new Locale (first , second , third );
437
445
}
438
446
}
439
-
440
- private boolean _isScriptOrExtensionPresent (String value ) {
441
- return value .contains ("_#" );
442
- }
443
447
}
444
448
445
449
// @since 2.12 to simplify logic a bit: should not use coercions when reading
0 commit comments