|
9 | 9 |
|
10 | 10 | import com.fasterxml.jackson.databind.*;
|
11 | 11 | import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
|
| 12 | +import com.fasterxml.jackson.databind.cfg.CoercionAction; |
| 13 | +import com.fasterxml.jackson.databind.cfg.CoercionInputShape; |
12 | 14 | import com.fasterxml.jackson.databind.deser.*;
|
13 | 15 | import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
|
14 | 16 | import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
|
@@ -246,7 +248,23 @@ public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt)
|
246 | 248 | // there is also possibility of "auto-wrapping" of single-element arrays.
|
247 | 249 | // Hence we only accept empty String here.
|
248 | 250 | 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 | + } |
250 | 268 | }
|
251 | 269 | return handleNonArray(p, ctxt, createDefaultInstance(ctxt));
|
252 | 270 | }
|
|
0 commit comments