-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectId does not properly handle forward reference during deserialization #351
Comments
The main problem, as I recall this, was that there was no way to hold on to accessors (SettableBeanProperty) along with instance it operators on, to use once actual object is resolved. Otherwise this would be relatively easy to support. It is also worth noting that many features, such as Maybe it would be possible to re-check this for 2.4 -- I put evaluation on hold earlier (with 2.2 I think). |
Yes, there is currently a lack of context when deserializing an Object Id and thus the SettableBeanProperty cannot be used. There might be some way around this though; like with Managed and Back reference, the "link" between the two properties is done with a specific SettableBeanProperty (ManagedReferenceProperty) which is constructed during BeanDeserializerBase#resolve. So it might be that any property that needs to handle an ObjectId will need its own SettableBeanProperty implementation? A solution to chicken-and-egg might be to create a temporary object when deserializing from an Object Id that isn't resolved, and then update that instance when the object proper is found. This is an approach that I've used in the past, but it was not done in a generic way like Jackson has to deal with, so it might not be applicable. Specifically, if the object doesn't have any setter to use for updating, then it can't be done. As I said, I'm willing to work on this and perhaps provide an initial implementation. I need this sort of handling for the project I'm currently working on, so instead of writing custom handling for every case I encounter I'd rather fix this directly in Jackson |
Actually 2.3.0 added general-purpose feature of "Attributes", as per: http://www.cowtowncoder.com/blog/archives/2013/11/entry_483.html which allows for storing state. This could -- for example -- be a mapping from Object reference to property + POJO combination. So there is now simple contextual per-call storage available. Use of |
Thanks, I'll take a look at this. |
Progress has been made! You can look at the working branch to see how things are going. I used your idea of throwing an exception, it definitely fits the problem. Next up is handling of array deserialization and a check at the end of processing to ensure are forward references are resolved and throw a proper exception if not, probably re-using info from previous exception that were thrown to handle forward reference. |
Great to hear. This is probably the highest-priority problem with existing code. |
I was able to squeeze more time to work on this. Unit tests (failing) have been added for various configuration which doesn't properly handle forward reference. I've also implemented the check at the end of processing which throw an exception about all unresolved forward reference at that point. It's currently missing information about the type which was expected, but a small modification to jackson-annotation (adding getters to So, right now, current handling works for most |
Sounds good so far. Just make sure to locate failing tests under Since an addition is needed in |
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):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.
The text was updated successfully, but these errors were encountered: