JsonRPC camelCase and Case Insensitive

This commit is contained in:
Kevin Zhang 2021-07-05 11:03:07 +08:00
parent d6ec4b51d5
commit 908d1c4124
2 changed files with 13 additions and 15 deletions

View file

@ -30,12 +30,8 @@ namespace Flow.Launcher.Core.Plugin
public string Data { get; set; }
}
public class JsonRPCModelBase
{
public int Id { get; set; }
}
public class JsonRPCResponseModel : JsonRPCModelBase
public class JsonRPCResponseModel
{
public string Result { get; set; }
@ -49,18 +45,20 @@ namespace Flow.Launcher.Core.Plugin
public string DebugMessage { get; set; }
}
public class JsonRPCRequestModel : JsonRPCModelBase
public class JsonRPCRequestModel
{
[JsonPropertyName("method")]
public string Method { get; set; }
[JsonPropertyName("parameters")]
public object[] Parameters { get; set; }
private static readonly JsonSerializerOptions options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public override string ToString()
{
return JsonSerializer.Serialize(this);
return JsonSerializer.Serialize(this, options);
}
}
@ -77,7 +75,6 @@ namespace Flow.Launcher.Core.Plugin
/// </summary>
public class JsonRPCClientRequestModel : JsonRPCRequestModel
{
[JsonPropertyName("dontHideAfterAction")]
public bool DontHideAfterAction { get; set; }
}

View file

@ -47,8 +47,9 @@ namespace Flow.Launcher.Core.Plugin
}
}
private static readonly JsonSerializerOptions _options = new()
private static readonly JsonSerializerOptions options = new()
{
PropertyNameCaseInsensitive = true,
Converters =
{
new JsonObjectConverter()
@ -60,7 +61,7 @@ namespace Flow.Launcher.Core.Plugin
if (output == Stream.Null) return null;
var queryResponseModel = await
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, _options);
JsonSerializer.DeserializeAsync<JsonRPCQueryResponseModel>(output, options);
return ParseResults(queryResponseModel);
}
@ -70,7 +71,7 @@ namespace Flow.Launcher.Core.Plugin
if (string.IsNullOrEmpty(output)) return null;
var queryResponseModel =
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, _options);
JsonSerializer.Deserialize<JsonRPCQueryResponseModel>(output, options);
return ParseResults(queryResponseModel);
}
@ -110,7 +111,7 @@ namespace Flow.Launcher.Core.Plugin
return !result.JsonRPCAction.DontHideAfterAction;
}
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, _options);
var jsonRpcRequestModel = JsonSerializer.Deserialize<JsonRPCRequestModel>(actionResponse, options);
if (jsonRpcRequestModel?.Method?.StartsWith("Flow.Launcher.") ?? false)
{