{"record":{"id":"a17735df6b965dd5","repo":"FasterXML/jackson-databind","slug":"could-not-resolve-object-id-for","errorCode":null,"errorMessage":"Could not resolve Object Id [{}] (for {}).","messagePattern":"Could not resolve Object Id \\[(.+?)\\] \\(for (.+?)\\)\\.","errorType":"exception","errorClass":"UnresolvedForwardReference","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/bean/BeanDeserializerBase.java","lineNumber":1653,"sourceCode":"    protected Object deserializeWithObjectId(JsonParser p, DeserializationContext ctxt)\n        throws JacksonException\n    {\n        return deserializeFromObject(p, ctxt);\n    }\n\n    /**\n     * Method called in cases where it looks like we got an Object Id\n     * to parse and use as a reference.\n     */\n    protected Object deserializeFromObjectId(JsonParser p, DeserializationContext ctxt)\n        throws JacksonException\n    {\n        Object id = _objectIdReader.readObjectReference(p, ctxt);\n        ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);\n        // do we have it resolved?\n        Object pojo = roid.resolve();\n        if (pojo == null) { // not yet; should wait...\n            throw new UnresolvedForwardReference(p,\n                    \"Could not resolve Object Id [\"+id+\"] (for \"+_beanType+\").\",\n                    p.currentLocation(), roid);\n        }\n        return pojo;\n    }\n\n    protected Object deserializeFromObjectUsingNonDefault(JsonParser p,\n            DeserializationContext ctxt)\n        throws JacksonException\n    {\n        // 02-Jul-2024, tatu: [databind#4602] Need to tweak regular and \"array\" delegating\n        //   Creator handling\n        final ValueDeserializer<Object> delegateDeser = _delegateDeserializer(p);\n        if (delegateDeser != null) {\n            // [databind#5909]: signal delegate-bind-pending so that any ROID\n            // bound during delegate deserialization retains resolved Referrings\n            // — needed for collection-property forward refs to be rebound after\n            // updateObjectId(delegate, bean) below.","sourceCodeStart":1635,"sourceCodeEnd":1671,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/deser/bean/BeanDeserializerBase.java#L1635-L1671","documentation":"Thrown as an UnresolvedForwardReference by BeanDeserializerBase.deserializeFromObjectId when an object identity reference is encountered (via @JsonIdentityInfo) but the referenced object has not yet been resolved. This means the id was registered with a ReadableObjectId but resolve() returned null — the object was never fully deserialized. Unlike a simple missing id, this specifically creates an UnresolvedForwardReference with location info so it can potentially be resolved later.","triggerScenarios":"JSON with @JsonIdentityInfo where an object id is referenced before it is defined (true forward reference) and the stream ends without the referenced object appearing. Circular references that are not properly handled. An id generator that produces ids not matching the references.","commonSituations":"Serializing a graph with bidirectional relationships using @JsonIdentityInfo where the deserialization order does not match. Missing or incomplete JSON (truncated stream). Using PROPERTY-based id generation where the id property is absent or mismatched. Polymorphic type processing interfering with identity resolution.","solutions":["Ensure the JSON fully contains all referenced objects — no truncation or missing entries.","Check @JsonIdentityInfo scope matches between serialization and deserialization (scope must be the same class or a common base).","If dealing with forward references, handle UnresolvedForwardReference by calling resolveId on the DeserializationContext after the full document is parsed.","Verify the id generator type (ObjectIdGenerators) is consistent between serialization and deserialization configurations."],"exampleFix":"// before: JSON references id 2 before it appears\n{\"ref\":2}\n// after: include the referenced object\n{\"@id\":2,\"name\":\"x\",\"ref\":2}","handlingStrategy":"try-catch","validationCode":"// Pre-validate that the JSON stream contains all referenced ids\nJsonNode tree = mapper.readTree(json);\nSet<Object> definedIds = extractIds(tree);\nSet<Object> referencedIds = extractRefs(tree);\nif (!definedIds.containsAll(referencedIds)) {\n    referencedIds.removeAll(definedIds);\n    throw new IllegalStateException(\"Missing object ids: \" + referencedIds);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return mapper.readValue(json, MyClass.class);\n} catch (UnresolvedForwardReference e) {\n    // Optionally: attempt to resolve from a secondary source, or report gracefully\n    logger.error(\"Unresolved object id '{}' at {}\", e.getUnresolvedId(), e.getLocation());\n    throw e;\n}","preventionTips":["Ensure JSON graphs are complete — all referenced objects must be defined.","Verify @JsonIdentityInfo scope is consistent between producer and consumer.","For forward references, use two-pass parsing: parse, then resolve pending refs."],"tags":["jackson","deserialization","forward-reference","json-identity","object-id"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}