Skip to content

Self-referencing type with property-level @JsonIdentityInfo: nested value misses settings applied later in resolve() #6359

Open

Description

@cowtowncoder

Describe the issue

When a type refers to itself through a property with property-level @JsonIdentityInfo, the contextual (Object Id) deserializer for that property is created while the type's own deserializer is still inside BeanDeserializerBase.resolve(). withObjectIdReader() takes a copy of the BeanPropertyMap at that point. So changes resolve() makes to properties after the self-referencing one (null handling, managed/back references, and so on) are applied only to the original map, not to the copy used for nested values.

Before #6358 (fix for #6352) this case failed outright with NoSuchElementException: No entry 'next' found, can't replace, because the map was modified in place. After #6358 it no longer fails, but nested values are deserialized without those settings.

Version

3.4.0-SNAPSHOT (with #6358)

Reproduction

@JsonPropertyOrder({"id", "next", "z"})
static class Node {
    public int id;
    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
    public Node next;
    @JsonSetter(nulls = Nulls.FAIL)
    public String z;
}

ObjectMapper mapper = JsonMapper.shared();
// fails as expected with `InvalidNullException`:
mapper.readValue("""
    {"id":1,"z":null}
    """, Node.class);
// does NOT fail: `Nulls.FAIL` is not applied to the nested value
mapper.readValue("""
    {"id":1,"next":{"id":2,"z":null}}
    """, Node.class);

Expected behavior

Nested Node (via next) uses the same property settings as the root Node, so the second call also fails with InvalidNullException.

Notes

_contextualizeProperties() (from #1755) re-contextualizes value deserializers of the copy, but does not re-apply the other per-property changes from resolve(). A possible fix is to defer the Object Id copy, or to rebuild it once resolve() has finished.

Activity

  1. havefunatcode commented on Nov 5, 2026

    @havefunatcode

    Is anyone working on this? If not, I'd like to give it a try.

  2. cowtowncoder commented on Nov 5, 2026

    @cowtowncoder
    MemberAuthor

    @havefunatcode I don't think anyone is so go ahead (like you did it looks like)

  3. added a commit that references this issue on Nov 13, 2026
  4. added this to the 3.4.0 milestone on Nov 13, 2026
  5. added 2 commits that reference this issue on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions