Fix System.Text.Json formatter's support for named arguments object
Fixes #1028
This commit is contained in:
Родитель
9ff530296f
Коммит
2d8dfb1ddc
|
@ -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)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче