Skip to content

Commit 00c9b0a

Browse files
committed
Removing attribute-based JSON deserialization for .NET responses
This allows the Response object to be flexible enough to handle both the open-source and W3C dialects of the JSON wire protocol.
1 parent e790265 commit 00c9b0a

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

dotnet/src/webdriver/Remote/Response.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
using System.Globalization;
2020
using Newtonsoft.Json;
21+
using System.Collections.Generic;
22+
using System;
2123

2224
namespace OpenQA.Selenium.Remote
2325
{
@@ -49,11 +51,27 @@ public Response(SessionId sessionId)
4951
}
5052
}
5153

54+
private Response(Dictionary<string, object> rawResponse)
55+
{
56+
if (rawResponse.ContainsKey("sessionId"))
57+
{
58+
this.responseSessionId = rawResponse["sessionId"].ToString();
59+
}
60+
61+
if (rawResponse.ContainsKey("status"))
62+
{
63+
this.responseStatus = (WebDriverResult)Convert.ToInt32(rawResponse["status"]);
64+
}
65+
66+
if (rawResponse.ContainsKey("value"))
67+
{
68+
this.responseValue = rawResponse["value"];
69+
}
70+
}
71+
5272
/// <summary>
5373
/// Gets or sets the value from JSON.
5474
/// </summary>
55-
[JsonConverter(typeof(ResponseValueJsonConverter))]
56-
[JsonProperty("value")]
5775
public object Value
5876
{
5977
get { return this.responseValue; }
@@ -63,7 +81,6 @@ public object Value
6381
/// <summary>
6482
/// Gets or sets the session ID.
6583
/// </summary>
66-
[JsonProperty("sessionId")]
6784
public string SessionId
6885
{
6986
get { return this.responseSessionId; }
@@ -73,7 +90,6 @@ public string SessionId
7390
/// <summary>
7491
/// Gets or sets the status value of the response.
7592
/// </summary>
76-
[JsonProperty("status")]
7793
public WebDriverResult Status
7894
{
7995
get { return this.responseStatus; }
@@ -87,9 +103,9 @@ public WebDriverResult Status
87103
/// <returns>A <see cref="Response"/> object described by the JSON string.</returns>
88104
public static Response FromJson(string value)
89105
{
90-
JsonSerializerSettings settings = new JsonSerializerSettings();
91-
settings.DateParseHandling = DateParseHandling.None;
92-
return JsonConvert.DeserializeObject<Response>(value, settings);
106+
Dictionary<string, object> deserializedResponse = JsonConvert.DeserializeObject<Dictionary<string, object>>(value, new ResponseValueJsonConverter());
107+
Response response = new Response(deserializedResponse);
108+
return response;
93109
}
94110

95111
/// <summary>

0 commit comments

Comments
 (0)