-
-
Notifications
You must be signed in to change notification settings - Fork 8.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
[dotnet] Switch DevTools response JSON parsing to JsonElement
#14990
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
@@ -53,6 +54,6 @@ public DevToolsEventReceivedEventArgs(string domainName, string eventName, JsonN | |||
/// <summary> | |||
/// Gets the data with which the event is to be raised. | |||
/// </summary> | |||
public JsonNode EventData { get; private set; } | |||
public JsonElement EventData { get; private set; } |
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.
This is used all across cdp generated code. Luckily, the generated code looks like var eventArgs = e.EventData.Deserialize(eventData.EventArgsType);
which is exactly the same when EventData
is either JsonNode
or JsonElement
.
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Switches JSON response parsing in DevTools from mutable
JsonNode
to immutableJsonElement
.Motivation and Context
In general,
JsonElement
is preferred if the JSON is not being mutated. But the true motivation is from #14972.JsonElement
is a lot more forgiving of imperfect json (it allows multiple properties with the same name, it doesn't throw exceptions on invalid UTF-16 before the deserialization converters apply, etc).This will allow us to Eventually fortify the code against invalid JSON, which is the root cause of #14903.
Types of changes
Checklist
PR Type
Bug fix, Enhancement
Description
JsonNode
to immutableJsonElement
across multiple filesJsonElement
which is more forgiving of imperfect JSONChanges walkthrough 📝
DevToolsCommandData.cs
Switch Result property to JsonElement type
dotnet/src/webdriver/DevTools/DevToolsCommandData.cs
Result
property type fromJsonNode
toJsonElement
DevToolsSession.cs
Refactor JSON handling to use JsonElement
dotnet/src/webdriver/DevTools/DevToolsSession.cs
JsonElement
instead ofJsonNode
DevToolsSessionEventReceivedEventArgs.cs
Update EventData to use JsonElement
dotnet/src/webdriver/DevTools/DevToolsSessionEventReceivedEventArgs.cs
EventData
property type fromJsonNode
toJsonElement
IDevToolsSession.cs
Update SendCommand return type to JsonElement
dotnet/src/webdriver/DevTools/IDevToolsSession.cs
SendCommand
fromJsonNode
toJsonElement?