-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Error Being thrown for Duplicate properties #29873
Comments
@Anipik, when do you plan to submit a fix for this issue? |
@ahsonkhan i tested two strategies here 1) with hashset 2) with linq. The change is not effecting the performance. (It might need a little bit more testing). I recalled you wanted to take a look at the hashset change. i am side tracked by a .NetFramework bug, but i think i will be able to make a final PR(after performance stuff) by wednesday |
Sounds good. cc @steveharter |
In Json.NET there is a setting for it. It concatenates by default, but in hindsight I think replacing is better. IMO you should replace by default, and if you want to you could add a setting post 3.0 to support adding collection values into existing collections and populating properties onto existing objects. |
aside: "replace" vs. "add" semantics applies both to cases where there at pre-existing values in the object (set from the ctor, for example) and also having duplicate properties in the JSON. I think these should be treated the same. If we have replace semantics, then we have to decide whether to re-set the property with a new list\etc instance or attempt to call "Clear". However, not all collections support "Clear" (readonly), and arrays don't. So it appears the most straightforward option is to call the setter again with a new instance (list or array) on the property. This requires the property have a setter plus it will replace any instance the user may have created, which might not be a nice thing for polymorphic scenarios (for example, the ctor may have assigned a custom collection on a IList property where we would replace with I suppose we could attempt to get the count\length and only replace if >0 so we can preserve the existing instance (if there is one)? |
That's what Json.NET does. ObjectCreationHandling covers both objects and collections. https://www.newtonsoft.com/json/help/html/DeserializeObjectCreationHandling.htm
Set a new list. |
The issue with the lists and arrays is tracked by https://github.com/dotnet/corefx/issues/38435 so closing this one. |
https://github.com/dotnet/corefx/blob/master/src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs#L80
This error gets thrown when we try to deserialize Dicitonary with duplicate properties (As it increases the count). However it might now throw and give random output if the cacheCount is lesss than propertyRefCount
The text was updated successfully, but these errors were encountered: