Skip to content

Commit 4dbe411

Browse files
committed
Use JsonNode instead of JsonDocument
1 parent 1080a74 commit 4dbe411

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Text.Json;
24+
using System.Text.Json.Nodes;
2425
using System.Text.Json.Serialization;
2526

2627
#nullable enable
@@ -31,8 +32,9 @@ internal class GetClientWindowsResultConverter : JsonConverter<GetClientWindowsR
3132
{
3233
public override GetClientWindowsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3334
{
34-
using var doc = JsonDocument.ParseValue(ref reader);
35-
var clientWindows = doc.RootElement.GetProperty("clientWindows").Deserialize<IReadOnlyList<ClientWindowInfo>>(options);
35+
var jsonNode = JsonNode.Parse(ref reader);
36+
37+
var clientWindows = jsonNode?["clientWindows"].Deserialize<IReadOnlyList<ClientWindowInfo>>(options);
3638

3739
return new GetClientWindowsResult(clientWindows!);
3840
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Text.Json;
24+
using System.Text.Json.Nodes;
2425
using System.Text.Json.Serialization;
2526

2627
#nullable enable
@@ -31,9 +32,10 @@ internal class GetCookiesResultConverter : JsonConverter<GetCookiesResult>
3132
{
3233
public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3334
{
34-
using var doc = JsonDocument.ParseValue(ref reader);
35-
var cookies = doc.RootElement.GetProperty("cookies").Deserialize<IReadOnlyList<Modules.Network.Cookie>>(options);
36-
var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize<PartitionKey>(options);
35+
var jsonNode = JsonNode.Parse(ref reader);
36+
37+
var cookies = jsonNode?["cookies"].Deserialize<IReadOnlyList<Modules.Network.Cookie>>(options);
38+
var partitionKey = jsonNode?["partitionKey"].Deserialize<PartitionKey>(options);
3739

3840
return new GetCookiesResult(cookies!, partitionKey!);
3941
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Text.Json;
24+
using System.Text.Json.Nodes;
2425
using System.Text.Json.Serialization;
2526

2627
#nullable enable
@@ -31,8 +32,9 @@ internal class GetRealmsResultConverter : JsonConverter<GetRealmsResult>
3132
{
3233
public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3334
{
34-
using var doc = JsonDocument.ParseValue(ref reader);
35-
var realms = doc.RootElement.GetProperty("realms").Deserialize<IReadOnlyList<RealmInfo>>(options);
35+
var jsonNode = JsonNode.Parse(ref reader);
36+
37+
var realms = jsonNode?["realms"].Deserialize<IReadOnlyList<RealmInfo>>(options);
3638

3739
return new GetRealmsResult(realms!);
3840
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Text.Json;
24+
using System.Text.Json.Nodes;
2425
using System.Text.Json.Serialization;
2526

2627
#nullable enable
@@ -31,8 +32,9 @@ internal class GetUserContextsResultConverter : JsonConverter<GetUserContextsRes
3132
{
3233
public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3334
{
34-
using var doc = JsonDocument.ParseValue(ref reader);
35-
var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize<IReadOnlyList<UserContextInfo>>(options);
35+
var jsonNode = JsonNode.Parse(ref reader);
36+
37+
var userContexts = jsonNode?["userContexts"].Deserialize<IReadOnlyList<UserContextInfo>>(options);
3638

3739
return new GetUserContextsResult(userContexts!);
3840
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Text.Json;
25+
using System.Text.Json.Nodes;
2526
using System.Text.Json.Serialization;
2627

2728
#nullable enable
@@ -32,8 +33,9 @@ internal class LocateNodesResultConverter : JsonConverter<LocateNodesResult>
3233
{
3334
public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3435
{
35-
using var doc = JsonDocument.ParseValue(ref reader);
36-
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<RemoteValue.Node>>(options);
36+
var jsonNode = JsonNode.Parse(ref reader);
37+
38+
var nodes = jsonNode?["qwe"].Deserialize<IReadOnlyList<RemoteValue.Node>>(options);
3739

3840
return new LocateNodesResult(nodes!);
3941
}

0 commit comments

Comments
 (0)