-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Json.NET deserializes nested types using only the last entry in the nested array #2955
Comments
Not a bug. However, you are not the first and will not be the last whose intuitive assumptions about Newtonsoft.Json's serialization behavior is in conflict with the actual default behavior of Newtonsoft.Json. See #2923 (comment) and also the documentation for In essence, you would have to configure the serialization setting
That is astronomically unlikely to happen, considering that the solution to this problem is to configure the (de)serializer appropriately, which is easy to do. Changing the default behavior of the (de)serializer, one that is already established for a long time, would be an breaking change; basically a no-go, considering how many (legacy) projects and deployments use Newtonsoft.Json.
If this implies you migrated to System.Text.Json, then that's in my opinion the best solution by far, and there should be no reason to go back to Newtonsoft.Json. |
I'm very confused becasue this started happening without us realising it, and after so many years i had no idea about the behaviour of ObjectCreationHandling. May I suggest that, at least for me as a non-english speaker, https://www.newtonsoft.com/json/help/html/SerializationSettings.htm did not quite make me expect what the bheaviour was, and that I'd be happpy to contribute some content if you have FAQs or elsewhere so it is more obvious that on a nested object reuse would be used even if the content is different? Either way let me know if I can help. I'll close the bug as invalid as it is properly documented. |
ObjectA -> Results[] -> Result -> Vaiable
Only the last variable in the series is taken into account, causing absolue havoc.
I added a full repro of the wrong assertion that passes (all variables are the same) followed by the correct assertions (which fail).
We've had to hotfix by removing json.net alltogether unfortunately, but I hope this helps teh next version fix it, or help me understand where i did something wrong.
Archive.zip
The text was updated successfully, but these errors were encountered: