Open
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When using System.Text.Json, patches to dynamic objects using the non-generic type JsonPatchDocument are not processed correctly.
The CanRead method of the NewtonsoftJsonPatchInputFormatter class does not allow non-generic types.
With this behavior, patch requests are not handled correctly and the InputFormatter falls back to the default of System.Text.Json, which cannot deserialize this request into a suitable object.
public override bool CanRead(InputFormatterContext context)
{
ArgumentNullException.ThrowIfNull(context);
var modelType = context.ModelType;
if (!typeof(IJsonPatchDocument).IsAssignableFrom(modelType) ||
!modelType.IsGenericType)
{
return false;
}
return base.CanRead(context);
}
Expected Behavior
Perhaps the type should be treated explicitly
public override bool CanRead(InputFormatterContext context)
{
ArgumentNullException.ThrowIfNull(context);
var modelType = context.ModelType;
if (!typeof(IJsonPatchDocument).IsAssignableFrom(modelType) ||
!(modelType.IsGenericType && modelType.Equals(typeof(JsonPatchDocument))))
{
return false;
}
return base.CanRead(context);
}
Steps To Reproduce
- Setup a project like described
- Create Endpoint for dynamic objects
- Send Request to Endpoint
Exceptions (if any)
No response
.NET Version
.NET 8.0
Anything else?
No response
Activity