Fix System.Text.Json formatter's support for named arguments object

Fixes #1028
This commit is contained in:
Andrew Arnott 2024-05-17 14:48:49 -06:00
Родитель 9ff530296f
Коммит 2d8dfb1ddc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F33A420C60ED9C6F
2 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -487,9 +487,8 @@ public class SystemTextJsonFormatter : FormatterBase, IJsonRpcMessageFormatter,
using (this.formatter.TrackDeserialization(this, parameters))
{
// Support for opt-in to deserializing all named arguments into a single parameter.
if (parameters.Length == 1 && this.formatter.ApplicableMethodAttributeOnDeserializingMethod?.UseSingleObjectParameterDeserialization is true)
if (parameters.Length == 1 && this.formatter.ApplicableMethodAttributeOnDeserializingMethod?.UseSingleObjectParameterDeserialization is true && this.JsonArguments is not null)
{
Assumes.NotNull(this.JsonArguments);
typedArguments[0] = this.JsonArguments.Value.Deserialize(parameters[0].ParameterType, this.formatter.massagedUserDataSerializerOptions);
return ArgumentMatchResult.Success;
}

Просмотреть файл

@ -1453,6 +1453,13 @@ public abstract class JsonRpcTests : TestBase
Assert.Equal(7, sum);
}
[Fact]
public async Task InvokeWithSingleObjectParameter_SupplyNoArgument()
{
int sum = await this.clientRpc.InvokeWithParameterObjectAsync<int>(nameof(Server.MethodWithSingleObjectParameterWithDefaultValue), cancellationToken: this.TimeoutToken);
Assert.Equal(-1, sum);
}
[Fact]
public async Task InvokeWithSingleObjectParameter_SendingExpectedObjectAndCancellationToken_InterfaceMethodAttributed()
{
@ -3337,6 +3344,12 @@ public abstract class JsonRpcTests : TestBase
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)
{