Skip to content

Commit 908d1c4

Browse files
committed
JsonRPC camelCase and Case Insensitive
1 parent d6ec4b5 commit 908d1c4

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

Flow.Launcher.Core/Plugin/JsonPRCModel.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ public class JsonRPCErrorModel
3030
public string Data { get; set; }
3131
}
3232

33-
public class JsonRPCModelBase
34-
{
35-
public int Id { get; set; }
36-
}
3733

38-
public class JsonRPCResponseModel : JsonRPCModelBase
34+
public class JsonRPCResponseModel
3935
{
4036
public string Result { get; set; }
4137

@@ -49,18 +45,20 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel
4945

5046
public string DebugMessage { get; set; }
5147
}
52-
53-
public class JsonRPCRequestModel : JsonRPCModelBase
48+
49+
public class JsonRPCRequestModel
5450
{
55-
[JsonPropertyName("method")]
5651
public string Method { get; set; }
5752

58-
[JsonPropertyName("parameters")]
5953
public object[] Parameters { get; set; }
6054

55+
private static readonly JsonSerializerOptions options = new()
56+
{
57+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
58+
};
6159
public override string ToString()
6260
{
63-
return JsonSerializer.Serialize(this);
61+
return JsonSerializer.Serialize(this, options);
6462
}
6563
}
6664

@@ -77,7 +75,6 @@ public class JsonRPCServerRequestModel : JsonRPCRequestModel
7775
/// </summary>
7876
public class JsonRPCClientRequestModel : JsonRPCRequestModel
7977
{
80-
[JsonPropertyName("dontHideAfterAction")]
8178
public bool DontHideAfterAction { get; set; }
8279
}
8380

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public List<Result> LoadContextMenus(Result selectedResult)
4747
}
4848
}
4949

50-
private static readonly JsonSerializerOptions _options = new()
50+
private static readonly JsonSerializerOptions options = new()
5151
{
52+
PropertyNameCaseInsensitive = true,
5253
Converters =
5354
{
5455
new JsonObjectConverter()
@@ -60,7 +61,7 @@ private async Task<List<Result>> DeserializedResultAsync(Stream output)
6061
if (output == Stream.Null) return null;
6162

6263
var queryResponseModel = await
63-
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, _options);
64+
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, options);
6465

6566
return ParseResults(queryResponseModel);
6667
}
@@ -70,7 +71,7 @@ private List<Result> DeserializedResult(string output)
7071
if (string.IsNullOrEmpty(output)) return null;
7172

7273
var queryResponseModel =
73-
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, _options);
74+
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, options);
7475
return ParseResults(queryResponseModel);
7576
}
7677

@@ -110,7 +111,7 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
110111
return !result.JsonRPCAction.DontHideAfterAction;
111112
}
112113

113-
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
114+
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, options);
114115

115116
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
116117
{

0 commit comments

Comments
 (0)