Skip to content

Commit fa1dfcf

Browse files
author
Pedro López Cabanillas
committed
Allow jsonrpc property (version) to be setable
1 parent 488e077 commit fa1dfcf

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

Json-Rpc/JsonResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace AustinHarris.JsonRpc
1313
public class JsonResponse
1414
{
1515
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "jsonrpc")]
16-
public string JsonRpc { get { return "2.0"; } }
16+
public string JsonRpc { get; set; } = "2.0";
1717

1818
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "result")]
1919
public object Result { get; set; }
@@ -32,7 +32,7 @@ public class JsonResponse
3232
public class JsonResponse<T>
3333
{
3434
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "jsonrpc")]
35-
public string JsonRpc { get { return "2.0"; } }
35+
public string JsonRpc { get; set; } = "2.0";
3636

3737
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "result")]
3838
public T Result { get; set; }

Json-Rpc/JsonRpcProcessor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j
101101

102102
if (data == null) continue;
103103

104+
jsonResponse.JsonRpc = data.JsonRpc;
104105
jsonResponse.Error = data.Error;
105106
jsonResponse.Result = data.Result;
106107

@@ -119,8 +120,10 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j
119120
StringWriter sw = new StringWriter();
120121
JsonTextWriter writer = new JsonTextWriter(sw);
121122
writer.WriteStartObject();
122-
writer.WritePropertyName("jsonrpc"); writer.WriteValue("2.0");
123-
123+
if (!string.IsNullOrEmpty(jsonResponse.JsonRpc))
124+
{
125+
writer.WritePropertyName("jsonrpc"); writer.WriteValue(jsonResponse.JsonRpc);
126+
}
124127
if (jsonResponse.Error != null)
125128
{
126129
writer.WritePropertyName("error"); writer.WriteRawValue(JsonConvert.SerializeObject(jsonResponse.Error));

0 commit comments

Comments
 (0)