Skip to content

Commit 3ae6c62

Browse files
committed
Add release notes for #3259
1 parent bd5782b commit 3ae6c62

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -1388,3 +1388,7 @@ Tanvesh Takawale (TanveshT@github)
13881388
Hyeonho Kim (proost@github)
13891389
* Contributed fix for #3227: Content `null` handling not working for root values
13901390
(2.13.0)
1391+
1392+
Abishek Ravichandran (abrav9595@github)
1393+
* Contributed #3259: Support for BCP 47 `java.util.Locale` serialization/deserialization
1394+
(2.13.0)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Project: jackson-databind
7171
(contributed by Tanvesh)
7272
#3244: StackOverflowError when serializing JsonProcessingException
7373
(reported by saneksanek@github)
74+
#3259: Support for BCP 47 `java.util.Locale` serialization/deserialization
75+
(contributed by Abishek R)
7476
- Fix to avoid problem with `BigDecimalNode`, scale of `Integer.MIN_VALUE` (see
7577
[dataformats-binary#264] for details)
7678
- Extend handling of `FAIL_ON_NULL_FOR_PRIMITIVES` to cover coercion from (Empty) String

src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java

+33-29
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ public static class Std extends FromStringDeserializer<Object>
282282
// No longer implemented here since 2.12
283283
// public final static int STD_STRING_BUILDER = 13;
284284

285+
protected final static String LOCALE_EXT_MARKER = "_#";
286+
285287
protected final int _kind;
286288

287289
protected Std(Class<?> valueType, int kind) {
@@ -315,25 +317,7 @@ protected Object _deserialize(String value, DeserializationContext ctxt) throws
315317
// will throw IAE (or its subclass) if malformed
316318
return Pattern.compile(value);
317319
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);
337321
case STD_CHARSET:
338322
return Charset.forName(value);
339323
case STD_TIME_ZONE:
@@ -402,17 +386,41 @@ protected int _firstHyphenOrUnderscore(String str)
402386
return -1;
403387
}
404388

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+
405414
private Locale _deSerializeBCP47Locale(String value, int ix, String first, String second) {
406415
String third = "";
407416
try {
408417
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) {
415422
third = value.substring(ix + 1, scriptExpIx);
423+
}
416424
value = value.substring(scriptExpIx + 2);
417425

418426
if (value.indexOf('_') < 0 && value.indexOf('-') < 0) {
@@ -436,10 +444,6 @@ private Locale _deSerializeBCP47Locale(String value, int ix, String first, Strin
436444
return new Locale(first, second, third);
437445
}
438446
}
439-
440-
private boolean _isScriptOrExtensionPresent(String value) {
441-
return value.contains("_#");
442-
}
443447
}
444448

445449
// @since 2.12 to simplify logic a bit: should not use coercions when reading

0 commit comments

Comments
 (0)