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
Deserialization result error when two properties return the same collection object #4312
Comments
the version is 2.13.2 |
In future, please do not report against old versions: should be reproducible with 2.16(.1). Second: Lombok does bytecode manipulation so we would need to see actual class being used, not Lombok definition (since it is different from declaration, adding possible setters/getters/fields). Beyond this it'd be necessary to see the actual class: this may be due to non-obvious feature where "getter" can be used to get collection for deserialization purpose (if no setter or field found). |
(wrong repo, moving to jackson-databind) |
I try the version of 2.16.1, it exists too.
And then,when I return a List with a new Object like
All in all, I think it's probably a good idea to do a clear on a collection that's been serialized using a getter. |
Or, if you need to deserialize a collection obtained using a getter, you need to check for the existence of a setter method (even if you don't use a setter method, you need to make sure the setter exists). It makes no sense to deserialize a logical property. Logical properties only need to be serialized, not deserialized. |
My problem here is that while I understand what Jackson does and why (despite possibly surprising behavior of I do not think there is anything that needs changing on Jackson side (USE_GETTERS_AS_SETTERS will be disabled by default for Jackson 3.0 as I don't think it is a good feature in general). But I would like to help you make things work the way they should, if possible. |
This is just a simple example. Real business scenarios can be much more complex. For example, to determine the value returned based on some conditions
It's similar to a view property, except that under certain conditions it actually returns the object of another property. |
Yes, that's fine -- user needs to be aware of linking between actual values and not create problematic data structures. Jackson does not, and should not try to track physical references across values: it operates on logical property values, based on possible annotations. |
At this point I am ready to close the issue, leaving open for a day or two for additional information on concrete problem to solve. One last thing I'll mention is that if actual Object identity needs to be retained (to avoid duplicate serialization as JSON, as well as re-link values on deserialization, there is a way to do that, using |
When two properties return the same object, deserialization results in double the number of elements in the collection being populated.
This is an example of minimal reproduction
More seriously, if such an object is subjected to the serialization and deserialization process over and over again, after a few times, it will cause a memory overflow.
The text was updated successfully, but these errors were encountered: