Skip to content

Commit 98c2320

Browse files
committed
Merge branch '2.12' of github.com:FasterXML/jackson-databind into 2.12
2 parents aa28860 + 2e06068 commit 98c2320

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import com.fasterxml.jackson.databind.*;
1111
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
12+
import com.fasterxml.jackson.databind.cfg.CoercionAction;
13+
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
1214
import com.fasterxml.jackson.databind.deser.*;
1315
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
1416
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
@@ -246,7 +248,23 @@ public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt)
246248
// there is also possibility of "auto-wrapping" of single-element arrays.
247249
// Hence we only accept empty String here.
248250
if (p.hasToken(JsonToken.VALUE_STRING)) {
249-
return _deserializeFromString(p, ctxt);
251+
// 05-Nov-2020, ckozak: As per [jackson-databind#2922] string values may be handled
252+
// using handleNonArray, however empty strings may result in a null or empty collection
253+
// depending on configuration.
254+
final CoercionAction act = ctxt.findCoercionAction(logicalType(), handledType(),
255+
CoercionInputShape.EmptyString);
256+
// 05-Nov-2020, ckozak: Unclear if TryConvert should return the default
257+
// conversion (null) or fall through to handleNonArray.
258+
if (act != null
259+
// handleNonArray may successfully deserialize the result (if
260+
// ACCEPT_SINGLE_VALUE_AS_ARRAY is enabled, for example) otherwise it
261+
// is capable of failing just as well as _deserializeFromEmptyString.
262+
&& act != CoercionAction.Fail
263+
// getValueAsString call is ordered last to avoid unnecessarily building a string value.
264+
&& p.getValueAsString().isEmpty()) {
265+
return (Collection<Object>) _deserializeFromEmptyString(
266+
p, ctxt, act, handledType(), "empty String (\"\")");
267+
}
250268
}
251269
return handleNonArray(p, ctxt, createDefaultInstance(ctxt));
252270
}

src/test/java/com/fasterxml/jackson/databind/convert/CoerceContainersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private void _verifyNoCoercion(JavaType targetType) throws Exception {
161161
fail("Should not pass");
162162
} catch (Exception e) {
163163
verifyException(e, "Cannot deserialize value of type");
164-
verifyException(e, "from empty String");
164+
verifyException(e, "from empty String", "from String value (token `JsonToken.VALUE_STRING`)");
165165
}
166166
}
167167

0 commit comments

Comments
 (0)