From 2d8dfb1ddcff40cfb5da4386d1ed11aa8fd91db0 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 17 May 2024 14:48:49 -0600 Subject: [PATCH] Fix System.Text.Json formatter's support for named arguments object Fixes #1028 --- src/StreamJsonRpc/SystemTextJsonFormatter.cs | 3 +-- test/StreamJsonRpc.Tests/JsonRpcTests.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/StreamJsonRpc/SystemTextJsonFormatter.cs b/src/StreamJsonRpc/SystemTextJsonFormatter.cs index 5e41a5fc..54893f80 100644 --- a/src/StreamJsonRpc/SystemTextJsonFormatter.cs +++ b/src/StreamJsonRpc/SystemTextJsonFormatter.cs @@ -487,9 +487,8 @@ public override ArgumentMatchResult TryGetTypedArguments(ReadOnlySpan(nameof(Server.MethodWithSingleObjectParameterWithDefaultValue), cancellationToken: this.TimeoutToken); + Assert.Equal(-1, sum); + } + [Fact] public async Task InvokeWithSingleObjectParameter_SendingExpectedObjectAndCancellationToken_InterfaceMethodAttributed() { @@ -3337,6 +3344,12 @@ public static int MethodWithSingleObjectParameterAndCancellationToken(XAndYPrope return fields.x + fields.y; } + [JsonRpcMethod(UseSingleObjectParameterDeserialization = true)] + public static int MethodWithSingleObjectParameterWithDefaultValue(XAndYProperties? arg = null) + { + return arg is not null ? arg.x + arg.y : -1; + } + [JsonRpcMethod("test/MethodWithSingleObjectParameterWithProgress", UseSingleObjectParameterDeserialization = true)] public static int MethodWithSingleObjectParameterWithProgress(XAndYPropertiesWithProgress fields) {