-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add JsonObject ordering and extension data support #51717
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
Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsAs a follow-up to #51025 add the features:
Minor items:
Fixes #51572
|
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonObject.List.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonObject.KeyCollection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonObject.KeyCollection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonObject.List.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonObject.List.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonObject.List.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonObject.List.cs
Outdated
Show resolved
Hide resolved
...ies/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonNodeConverter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Node/JsonNode.cs
Outdated
Show resolved
Hide resolved
| if (_dictionary != null) | ||
| { | ||
| return _dictionary.ContainsKey(propertyName); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem like the dictionary can be null if this method is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if this cannot be changed into an assert perhaps rewrite to return _dictionary?.ContainsKey(propertyName);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_dictionary can be null here whenever the threshold isn't hit yet. E.g.:
JsonObject jObject = JsonNode.Parse("{}").AsObject();
bool exists = jObject.ContainsKey("FOO");
As a follow-up to #51025 add the features:
JsonObjectextension properties via:[JsonExtensionData] public JsonObject ExtensionData {get; set;}JsonNodeout.(I)Dictionary<string, JsonElement>is supported as an extension property. SinceJsonElementis read-only, it can't be effectively used for modifying extension data, so supportingJsonObjectwill enable that scenario.List<>but once a threshold is hit an additionalDictionary<>is created for fast lookup by property name. Once the dictionary is created, both are kept in sync. Enumeration is always done by the list for deterministic ordering.Minor items:
System.Objectconverter to detect whether to useJsonElementor JsonNode. Previously, theJsonNodeconverter handled this and theSystem.Objectconverter only knew aboutJsonElement. That could cause issues for users that ask for the converter forSystem.Object.Fixes #51572
(no longer using an
IDictionaryfield; insteadDictionary<>used).