Skip to content

Commit 0d16604

Browse files
authored
Implement #3533: Delegate absent value handling for EXTERNAL_PROPERTY to underlying AsArrayTypeDeserializer (#3558)
1 parent 0eb7f08 commit 0d16604

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/impl/ExternalTypeHandler.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,19 @@ public Object complete(JsonParser p, DeserializationContext ctxt,
286286
} else {
287287
typeId = extProp.getDefaultTypeId();
288288
}
289-
} else if (_tokens[i] == null) {
290-
SettableBeanProperty prop = extProp.getProperty();
291-
if (prop.isRequired() ||
292-
ctxt.isEnabled(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY)) {
289+
}
290+
291+
if (_tokens[i] != null) {
292+
values[i] = _deserialize(p, ctxt, i, typeId);
293+
} else {
294+
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY)) {
295+
SettableBeanProperty prop = extProp.getProperty();
293296
ctxt.reportPropertyInputMismatch(_beanType, prop.getName(),
294297
"Missing property '%s' for external type id '%s'",
295298
prop.getName(), _properties[i].getTypePropertyName());
296299
}
297-
}
298-
if (_tokens[i] != null) {
299-
values[i] = _deserialize(p, ctxt, i, typeId);
300+
301+
values[i] = _deserializeMissingToken(p, ctxt, i, typeId);
300302
}
301303

302304
final SettableBeanProperty prop = extProp.getProperty();
@@ -356,6 +358,21 @@ protected final Object _deserialize(JsonParser p, DeserializationContext ctxt,
356358
return _properties[index].getProperty().deserialize(mp, ctxt);
357359
}
358360

361+
@SuppressWarnings("resource")
362+
protected final Object _deserializeMissingToken(JsonParser p, DeserializationContext ctxt,
363+
int index, String typeId) throws IOException
364+
{
365+
TokenBuffer merged = ctxt.bufferForInputBuffering(p);
366+
merged.writeStartArray();
367+
merged.writeString(typeId);
368+
merged.writeEndArray();
369+
370+
// needs to point to START_OBJECT (or whatever first token is)
371+
JsonParser mp = merged.asParser(p);
372+
mp.nextToken();
373+
return _properties[index].getProperty().deserialize(mp, ctxt);
374+
}
375+
359376
@SuppressWarnings("resource")
360377
protected final void _deserializeAndSet(JsonParser p, DeserializationContext ctxt,
361378
Object bean, int index, String typeId) throws IOException

0 commit comments

Comments
 (0)