-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
JsonBackReference is being set too late; breaks hashCode() #390
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
Comments
Ok. So the problem here is that the forward reference is set before back ref(s); and for your use case this causes issues. Implementation can be changed, but I would really want the unit test to verify this. |
Thinking about this bit more, I think that the Regardless, I will change the order of setting property values for 2.4, assuming no test failures occur. But if there are regressions this may need to be revisited, and possibly even reverted. |
You could be right. Basically the scenario is that the child cannot exist without the parent, and we would never move the child to a different parent. But I see your point; if the parent did change, then the hash code would also change, which is bad. Since filing this bug, we actually changed the way we do hashCode() for that object for other reasons (it's also used by Hibernate, which prefers to calculate hashCode and equals based on a unique id field). So regrettably, I don't have a use for this fix anymore, but thanks anyway. Please don't hesitate to revert if it causes trouble. |
@zAlbee Thank you for the update. I was guessing fix might not be needed; but in a way it may be slightly better order for things anyway. But it is good to know that reverting would not have significant effects at this point. |
I've mapped a parent-children relationship in Jackson like so:
and I am expecting the Jackson deserializer to properly set the value of Child.parent automatically.
I'm seeing an issue after deserialization of a parent (i.e. JSON to POJO), where set membership tests (
children.contains(...)
) don't work. This is a HashSet and the Child.hashCode() is implemented such that it uses all properties (including the value of Child.parent). I see that Child.parent is getting set for each child, but only AFTER hashCode() has been called already. Stepping through with a debugger the parent property is null at this point when Jackson callsset.add()
:This is with Jackson 2.1.4.
The text was updated successfully, but these errors were encountered: