Skip to content

Commit ce11121

Browse files
committed
Fix #398 for 2.3.2 as well
1 parent 75a9738 commit ce11121

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Version: 2.3.2 (xx-xxx-2014)
66
#379: Fix a problem with (re)naming of Creator properties; needed to make
77
Paranamer module work with NamingStrategy.
88
(reported by Chris P, cpilsworth@github)
9+
#398: Should deserialize empty (not null) URI from empty String
10+
(reported by pgieser@github)
911
- Added `BeanSerializerBase._serializeObjectId()` needed by modules that
1012
override standard BeanSerializer; specifically, XML module.
1113

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected FromStringDeserializer(Class<?> vc) {
2424
/* Deserializer implementations
2525
/**********************************************************
2626
*/
27-
27+
2828
@SuppressWarnings("unchecked")
2929
@Override
3030
public final T deserialize(JsonParser jp, DeserializationContext ctxt)
@@ -34,8 +34,7 @@ public final T deserialize(JsonParser jp, DeserializationContext ctxt)
3434
String text = jp.getValueAsString();
3535
if (text != null) { // has String representation
3636
if (text.length() == 0 || (text = text.trim()).length() == 0) {
37-
// 15-Oct-2010, tatu: Empty String usually means null, so
38-
return null;
37+
return _deserializeFromEmptyString();
3938
}
4039
try {
4140
T result = _deserialize(text, ctxt);
@@ -72,4 +71,5 @@ protected T _deserializeEmbedded(Object ob, DeserializationContext ctxt)
7271
+ob.getClass().getName()+" into "+_valueClass.getName());
7372
}
7473

74+
protected T _deserializeFromEmptyString() { return null; }
7575
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ protected URI _deserialize(String value, DeserializationContext ctxt)
135135
{
136136
return URI.create(value);
137137
}
138+
139+
@Override
140+
protected URI _deserializeFromEmptyString() {
141+
// [#398] Need to produce non-null URI from empty String
142+
return URI.create("");
143+
}
138144
}
139145

140146
public static class CurrencyDeserializer

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@ public void testURI() throws Exception
443443
{
444444
URI value = new URI("http://foo.com");
445445
assertEquals(value, MAPPER.readValue("\""+value.toString()+"\"", URI.class));
446+
447+
// [#398]
448+
value = MAPPER.readValue(quote(""), URI.class);
449+
assertNotNull(value);
450+
assertEquals(URI.create(""), value);
446451
}
447452

448453
/*

0 commit comments

Comments
 (0)