diff --git a/release-notes/VERSION b/release-notes/VERSION index dd48c17da2..709200082e 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -6,6 +6,8 @@ Version: 2.3.2 (xx-xxx-2014) #379: Fix a problem with (re)naming of Creator properties; needed to make Paranamer module work with NamingStrategy. (reported by Chris P, cpilsworth@github) +#398: Should deserialize empty (not null) URI from empty String + (reported by pgieser@github) - Added `BeanSerializerBase._serializeObjectId()` needed by modules that override standard BeanSerializer; specifically, XML module. diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java index 223b242f3a..47f7de9262 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java @@ -24,7 +24,7 @@ protected FromStringDeserializer(Class vc) { /* Deserializer implementations /********************************************************** */ - + @SuppressWarnings("unchecked") @Override public final T deserialize(JsonParser jp, DeserializationContext ctxt) @@ -34,8 +34,7 @@ public final T deserialize(JsonParser jp, DeserializationContext ctxt) String text = jp.getValueAsString(); if (text != null) { // has String representation if (text.length() == 0 || (text = text.trim()).length() == 0) { - // 15-Oct-2010, tatu: Empty String usually means null, so - return null; + return _deserializeFromEmptyString(); } try { T result = _deserialize(text, ctxt); @@ -72,4 +71,5 @@ protected T _deserializeEmbedded(Object ob, DeserializationContext ctxt) +ob.getClass().getName()+" into "+_valueClass.getName()); } + protected T _deserializeFromEmptyString() { return null; } } diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/JdkDeserializers.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/JdkDeserializers.java index 98af730c9a..de533bc360 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/JdkDeserializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/JdkDeserializers.java @@ -135,6 +135,12 @@ protected URI _deserialize(String value, DeserializationContext ctxt) { return URI.create(value); } + + @Override + protected URI _deserializeFromEmptyString() { + // [#398] Need to produce non-null URI from empty String + return URI.create(""); + } } public static class CurrencyDeserializer diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestSimpleTypes.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestSimpleTypes.java index 3440f79a5f..de80510fc5 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestSimpleTypes.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestSimpleTypes.java @@ -443,6 +443,11 @@ public void testURI() throws Exception { URI value = new URI("http://foo.com"); assertEquals(value, MAPPER.readValue("\""+value.toString()+"\"", URI.class)); + + // [#398] + value = MAPPER.readValue(quote(""), URI.class); + assertNotNull(value); + assertEquals(URI.create(""), value); } /*