Skip to content

Commit c443f16

Browse files
committed
Try to resolve 3.0 issues wrt #3259
1 parent 74e6bd6 commit c443f16

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/jdk/JDKFromStringDeserializer.java

+9
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ protected int _firstHyphenOrUnderscore(String str)
254254
private Locale _deserializeLocale(String value, DeserializationContext ctxt)
255255
throws JacksonException
256256
{
257+
// 10-Sep-2021, tatu: Looks like a simplified version might just work:
258+
return Locale.forLanguageTag(value);
259+
260+
// ... but leaving Jackson 2.13.0 implementation below in case inspiration might
261+
// be needed; feel free to remove once 3.0.0 is released
262+
/*
257263
int ix = _firstHyphenOrUnderscore(value);
258264
if (ix < 0) { // single argument
259265
return new Locale(value);
@@ -271,8 +277,10 @@ private Locale _deserializeLocale(String value, DeserializationContext ctxt)
271277
return new Locale(first, second, value.substring(ix+1));
272278
}
273279
return _deSerializeBCP47Locale(value, ix, first, second, extMarkerIx);
280+
*/
274281
}
275282

283+
/*
276284
private Locale _deSerializeBCP47Locale(String value, int ix, String first, String second,
277285
int extMarkerIx)
278286
{
@@ -307,6 +315,7 @@ private Locale _deSerializeBCP47Locale(String value, int ix, String first, Strin
307315
return new Locale(first, second, third);
308316
}
309317
}
318+
*/
310319

311320
static class StringBuilderDeserializer extends JDKFromStringDeserializer
312321
{

src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKStringLikeTypesTest.java

-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.nio.ByteBuffer;
66
import java.nio.charset.Charset;
77
import java.util.Currency;
8-
import java.util.Locale;
98
import java.util.UUID;
109
import java.util.regex.Pattern;
1110

@@ -129,16 +128,6 @@ public void testFile() throws Exception
129128
assertEquals(abs, result.getAbsolutePath());
130129
}
131130

132-
public void testLocale() throws IOException
133-
{
134-
assertEquals(new Locale("en"), MAPPER.readValue(q("en"), Locale.class));
135-
assertEquals(new Locale("es", "ES"), MAPPER.readValue(q("es_ES"), Locale.class));
136-
assertEquals(new Locale("FI", "fi", "savo"),
137-
MAPPER.readValue(q("fi_FI_savo"), Locale.class));
138-
assertEquals(new Locale("en", "US"),
139-
MAPPER.readValue(q("en-US"), Locale.class));
140-
}
141-
142131
public void testCharSequence() throws IOException
143132
{
144133
CharSequence cs = MAPPER.readValue("\"abc\"", CharSequence.class);

src/test/java/com/fasterxml/jackson/databind/deser/jdk/MapDeserializationTest.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ public void testEnumPolymorphicSerializationTest() throws Exception
357357
/* Test methods, maps with Date
358358
/**********************************************************
359359
*/
360+
360361
public void testDateMap() throws Exception
361362
{
362363
Date date1=new Date(123456000L);
@@ -419,19 +420,6 @@ public void testUUIDKeyMap() throws Exception
419420
assertEquals(key, ob);
420421
}
421422

422-
public void testLocaleKeyMap() throws Exception {
423-
Locale key = Locale.CHINA;
424-
String JSON = "{ \"" + key + "\":4}";
425-
Map<Locale, Object> result = MAPPER.readValue(JSON, new TypeReference<Map<Locale, Object>>() {
426-
});
427-
assertNotNull(result);
428-
assertEquals(1, result.size());
429-
Object ob = result.keySet().iterator().next();
430-
assertNotNull(ob);
431-
assertEquals(Locale.class, ob.getClass());
432-
assertEquals(key, ob);
433-
}
434-
435423
public void testCurrencyKeyMap() throws Exception {
436424
Currency key = Currency.getInstance("USD");
437425
String JSON = "{ \"" + key + "\":4}";

src/test/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializerTest.java

+39
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
11
package com.fasterxml.jackson.databind.deser.std;
22

3+
import java.io.IOException;
34
import java.util.Locale;
5+
import java.util.Map;
46

7+
import com.fasterxml.jackson.core.type.TypeReference;
58
import com.fasterxml.jackson.databind.BaseMapTest;
69
import com.fasterxml.jackson.databind.ObjectMapper;
710

811
public class FromStringDeserializerTest extends BaseMapTest
912
{
1013
private final Locale[] LOCALES = new Locale[]
1114
{Locale.CANADA, Locale.ROOT, Locale.GERMAN, Locale.CHINESE, Locale.KOREA, Locale.TAIWAN};
15+
16+
/*
17+
/**********************************************************************
18+
/* Test methods, old, from Jackson pre-2.13
19+
/**********************************************************************
20+
*/
21+
1222
private final ObjectMapper MAPPER = newJsonMapper();
1323

24+
public void testLocale() throws IOException
25+
{
26+
assertEquals(new Locale("en"), MAPPER.readValue(q("en"), Locale.class));
27+
assertEquals(new Locale("es", "ES"), MAPPER.readValue(q("es_ES"), Locale.class));
28+
assertEquals(new Locale("FI", "fi", "savo"),
29+
MAPPER.readValue(q("fi_FI_savo"), Locale.class));
30+
assertEquals(new Locale("en", "US"),
31+
MAPPER.readValue(q("en-US"), Locale.class));
32+
}
33+
34+
public void testLocaleKeyMap() throws Exception {
35+
Locale key = Locale.CHINA;
36+
String JSON = "{ \"" + key + "\":4}";
37+
Map<Locale, Object> result = MAPPER.readValue(JSON, new TypeReference<Map<Locale, Object>>() {
38+
});
39+
assertNotNull(result);
40+
assertEquals(1, result.size());
41+
Object ob = result.keySet().iterator().next();
42+
assertNotNull(ob);
43+
assertEquals(Locale.class, ob.getClass());
44+
assertEquals(key, ob);
45+
}
46+
47+
/*
48+
/**********************************************************************
49+
/* Test methods, advanced (2.13+) -- [databind#3259]
50+
/**********************************************************************
51+
*/
52+
1453
public void testLocaleDeserializeNonBCPFormat() throws Exception {
1554
Locale locale = new Locale("en", "US");
1655
Locale deSerializedLocale = MAPPER.readValue(MAPPER.writeValueAsString(locale), Locale.class);

src/test/java/com/fasterxml/jackson/failing/ConstructorDetector3241Test.java

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.lang.annotation.*;
44

5-
import com.fasterxml.jackson.annotation.JsonSetter;
65
import com.fasterxml.jackson.annotation.Nulls;
76

87
import com.fasterxml.jackson.databind.*;

0 commit comments

Comments
 (0)