Skip to content

ObjectId does not properly handle forward reference during deserialization #351

@pgelinas

Description

@pgelinas

While JACKSON-792 did add some support for forward reference, it only handles the case where the object referenced are in "cascade" and where the pass or re-ordering properties (see BeanDeserializerBase#deserializeWithObjectId) ensure that the id property is always read first. However, this isn't the case most of the time, especially when alwaysAsId is used during serialization; resulting json cannot be parsed back unless under very specific conditions. For example (this is actual json generated by Jackson in a test case):

{ "employees" : [ 
     { "id" : 1, "name" : "First", "manager" : null, "reports" : [ 2 ] }, 
     { "id" : 2, "name" : "Second", "manager" : 1, "reports" : [ ] }
] }

Can't be parsed because the "Second" employee isn't inside the json object structure of the first.

I've started to look how to fix this. It's an extremely tricky case, and it gets insane when collection of ids are involved (like the above example). I have some failing test cases ready that I'll attach in a PR shortly. I might need to discuss solution I'm going for here or on dev-list, just to be sure I'm not missing any crucial point. Also, any ideas anyone can provide will help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions