From d0ac4290a76f3c8e78f727cfb4fb8b02577dd0dd Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 4 Jul 2024 14:58:16 -0700 Subject: [PATCH] Fix for #4607: native ObjectId handling failure (#4612) --- release-notes/CREDITS-2.x | 5 +++++ release-notes/VERSION-2.x | 3 +++ .../fasterxml/jackson/databind/deser/BeanDeserializer.java | 7 +++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index a6beb70be5..222c2dfdff 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1779,3 +1779,8 @@ Peter Levart (plevart@github) * Reported, contributed fix for #4575: StdDelegatingSerializer does not consider a Converter that may return null for a non-null input (2.17.2) + +Susan Witts (susanw1@github) + * Reported #4607: `MismatchedInput`: No Object Id found for an instance of X to + assign to property '@id' + (2.17.2) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 86a5477772..16ece6f972 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,9 @@ Project: jackson-databind (reported by @dmelisso) #4595: No way to explicitly disable wrapping in custom annotation processor (reported by @SimonCockx) +#4607: `MismatchedInput`: No Object Id found for an instance of X to + assign to property '@id' + (reported by Susan W) #4610: `DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS` does not work when used with Polymorphic type handling (fix by Joo-Hyuk K) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java index 010d6a98df..ba7e34d9c9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java @@ -363,6 +363,8 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t final Object bean = _valueInstantiator.createUsingDefault(ctxt); // [databind#631]: Assign current value, to be accessible by custom deserializers p.assignCurrentValue(bean); + + // First: do we have native Object Ids (like YAML)? if (p.canReadObjectId()) { Object id = p.getObjectId(); if (id != null) { @@ -370,8 +372,9 @@ public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) t } } // [databind#3838]: since 2.16 Uniform handling of missing objectId - // only for the specific "empty JSON Object" case - if (_objectIdReader != null && p.hasTokenId(JsonTokenId.ID_END_OBJECT)) { + // only for the specific "empty JSON Object" case (and only for non-Native + // Object Ids, see [databind#4607] + else if (_objectIdReader != null && p.hasTokenId(JsonTokenId.ID_END_OBJECT)) { // [databind#4610]: check if we are to skip failure if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)) { ctxt.reportUnresolvedObjectId(_objectIdReader, bean);