@@ -248,23 +248,7 @@ public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt)
248
248
// there is also possibility of "auto-wrapping" of single-element arrays.
249
249
// Hence we only accept empty String here.
250
250
if (p .hasToken (JsonToken .VALUE_STRING )) {
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
- }
251
+ return _deserializeFromString (p , ctxt , p .getText ());
268
252
}
269
253
return handleNonArray (p , ctxt , createDefaultInstance (ctxt ));
270
254
}
@@ -300,6 +284,41 @@ public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
300
284
return typeDeserializer .deserializeTypedFromArray (p , ctxt );
301
285
}
302
286
287
+ /**
288
+ * Logic extracted to deal with incoming String value.
289
+ *
290
+ * @since 2.12
291
+ */
292
+ @ SuppressWarnings ("unchecked" )
293
+ protected Collection <Object > _deserializeFromString (JsonParser p , DeserializationContext ctxt ,
294
+ String value )
295
+ throws IOException
296
+ {
297
+ final Class <?> rawTargetType = handledType ();
298
+
299
+ // 05-Nov-2020, ckozak: As per [jackson-databind#2922] string values may be handled
300
+ // using handleNonArray, however empty strings may result in a null or empty collection
301
+ // depending on configuration.
302
+
303
+ // Start by verifying if we got empty/blank string since accessing
304
+ // CoercionAction may be costlier than String value we'll almost certainly
305
+ // need anyway
306
+ if (value .isEmpty ()) { // ... in future may want to allow blank, too?
307
+ CoercionAction act = ctxt .findCoercionAction (logicalType (), rawTargetType ,
308
+ CoercionInputShape .EmptyString );
309
+ act = _checkCoercionFail (ctxt , act , rawTargetType , value ,
310
+ "empty String (\" \" )" );
311
+ if (act != null ) {
312
+ // handleNonArray may successfully deserialize the result (if
313
+ // ACCEPT_SINGLE_VALUE_AS_ARRAY is enabled, for example) otherwise it
314
+ // is capable of failing just as well as _deserializeFromEmptyString.
315
+ return (Collection <Object >) _deserializeFromEmptyString (
316
+ p , ctxt , act , rawTargetType , "empty String (\" \" )" );
317
+ }
318
+ }
319
+ return handleNonArray (p , ctxt , createDefaultInstance (ctxt ));
320
+ }
321
+
303
322
/**
304
323
* @since 2.12
305
324
*/
0 commit comments