Skip to content

Commit 2d90441

Browse files
committed
Fix #1123
1 parent 89559a2 commit 2d90441

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Project: jackson-databind
1414
(reported by jefferyyuan@github)
1515
#1112: Detailed error message from custom key deserializer is discarded
1616
(contributed by Benson M)
17+
#1123: Serializing and Deserializing Locale.ROOT
18+
(reported by hookumsnivy@github)
1719

1820
2.6.5 (19-Jan-2016)
1921

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,14 @@ protected Object _deserialize(String value, DeserializationContext ctxt) throws
276276

277277
@Override
278278
protected Object _deserializeFromEmptyString() throws IOException {
279-
// As per [#398], URI requires special handling
279+
// As per [databind#398], URI requires special handling
280280
if (_kind == STD_URI) {
281281
return URI.create("");
282282
}
283+
// As per [databind#1123], Locale too
284+
if (_kind == STD_LOCALE) {
285+
return Locale.ROOT;
286+
}
283287
return super._deserializeFromEmptyString();
284288
}
285289
}

src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public static Collection<Map.Entry<Class<?>, Object>> all()
3737
sers.put(UUID.class, new UUIDSerializer());
3838
sers.put(java.util.regex.Pattern.class, sls);
3939
sers.put(Locale.class, sls);
40-
41-
sers.put(Locale.class, sls);
4240

4341
// then atomic types (note: AtomicReference needs better handling)
4442
sers.put(AtomicBoolean.class, AtomicBooleanSerializer.class);

src/test/java/com/fasterxml/jackson/databind/deser/TestJdkTypes.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ static class PrimitivesBean
3232
public double doubleValue = -1.0;
3333
}
3434

35-
// for [JACKSON-616]
3635
static class WrappersBean
3736
{
3837
public Boolean booleanValue;
@@ -140,19 +139,17 @@ public void testCurrency() throws IOException
140139
assertEquals(usd, new ObjectMapper().readValue(quote("USD"), Currency.class));
141140
}
142141

143-
/**
144-
* Test for [JACKSON-419]
145-
*/
146142
public void testLocale() throws IOException
147143
{
148144
assertEquals(new Locale("en"), MAPPER.readValue(quote("en"), Locale.class));
149145
assertEquals(new Locale("es", "ES"), MAPPER.readValue(quote("es_ES"), Locale.class));
150-
assertEquals(new Locale("FI", "fi", "savo"), MAPPER.readValue(quote("fi_FI_savo"), Locale.class));
146+
assertEquals(new Locale("FI", "fi", "savo"),
147+
MAPPER.readValue(quote("fi_FI_savo"), Locale.class));
148+
// [databind#1123]
149+
Locale loc = MAPPER.readValue(quote(""), Locale.class);
150+
assertSame(Locale.ROOT, loc);
151151
}
152152

153-
/**
154-
* Test for [JACKSON-420] (add DeserializationConfig.FAIL_ON_NULL_FOR_PRIMITIVES)
155-
*/
156153
public void testNullForPrimitives() throws IOException
157154
{
158155
// by default, ok to rely on defaults

src/test/java/com/fasterxml/jackson/databind/ser/TestJdkTypes.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ public class TestJdkTypes
2020
extends com.fasterxml.jackson.databind.BaseMapTest
2121
{
2222
private final ObjectMapper MAPPER = objectMapper();
23-
24-
/**
25-
* Unit test to catch bug [JACKSON-8].
26-
*/
27-
public void testBigDecimal()
28-
throws Exception
23+
24+
public void testBigDecimal() throws Exception
2925
{
3026
Map<String, Object> map = new HashMap<String, Object>();
3127
String PI_STR = "3.14159265";
@@ -34,8 +30,7 @@ public void testBigDecimal()
3430
assertEquals("{\"pi\":3.14159265}", str);
3531
}
3632

37-
public void testBigDecimalAsPlainString()
38-
throws Exception
33+
public void testBigDecimalAsPlainString() throws Exception
3934
{
4035
final ObjectMapper mapper = new ObjectMapper();
4136

@@ -46,10 +41,7 @@ public void testBigDecimalAsPlainString()
4641
String str = mapper.writeValueAsString(map);
4742
assertEquals("{\"pi\":3.00000000}", str);
4843
}
49-
50-
/**
51-
* Unit test related to [JACKSON-155]
52-
*/
44+
5345
public void testFile() throws IOException
5446
{
5547
// this may get translated to different representation on Windows, maybe Mac:
@@ -81,9 +73,11 @@ public void testLocale() throws IOException
8173
assertEquals(quote("en"), MAPPER.writeValueAsString(new Locale("en")));
8274
assertEquals(quote("es_ES"), MAPPER.writeValueAsString(new Locale("es", "ES")));
8375
assertEquals(quote("fi_FI_savo"), MAPPER.writeValueAsString(new Locale("FI", "fi", "savo")));
76+
77+
// [databind#1123]
78+
assertEquals(quote(""), MAPPER.writeValueAsString(Locale.ROOT));
8479
}
8580

86-
// [JACKSON-484]
8781
public void testInetAddress() throws IOException
8882
{
8983
assertEquals(quote("127.0.0.1"), MAPPER.writeValueAsString(InetAddress.getByName("127.0.0.1")));

0 commit comments

Comments
 (0)