Skip to content

Revert media type change for Newtonsoft JsonPatch package#65559

Open
halter73 wants to merge 2 commits intomainfrom
halter73/65325
Open

Revert media type change for Newtonsoft JsonPatch package#65559
halter73 wants to merge 2 commits intomainfrom
halter73/65325

Conversation

@halter73
Copy link
Member

@halter73 halter73 commented Feb 27, 2026

This reverts the media type change from #62988 from the Newtonsoft.Json-based Microsoft.AspNetCore.JsonPatch package because in addition to enhancing the OpenAPI metadata, it had the unintended consequence of requiring all JSON Patch requests use exactly the normative Content-Type: application/json-patch+json header. This caused requests using the previously allowed Content-Type: application/json header to fail with a 415 Unsupported Media type response. This regression was reported by multiple people.

This leaves the Microsoft.AspNetCore.JsonPatch.SystemTextJson package unchanged, since it was a NuGet package introduce for .NET 10 and therefore has no regression making us more comfortable with the stricter behavior.

An additional benefit of reverting the Newtonsoft.Json-based Microsoft.AspNetCore.JsonPatch changes is that the package should once again become usable from Blazor WASM since we're removing the newly-added <Reference Include="Microsoft.AspNetCore.Http.Abstractions" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />. The inability to reference the package in a Blazor WASM app was also a regression in .NET 10 reported by multiple people.

This adds new tests to verify PatchContentTypes_AreHandledAsExpected. The OpenApi tests were also updated to verify that the request media type inferred from the JsonPatchDocument parameter can be completely overridden.

Fixes #65325
Fixes #64330

I plan to backport this to .NET 10 for servicing once this is approved.

Copilot AI review requested due to automatic review settings February 27, 2026 22:20
@halter73 halter73 requested a review from a team as a code owner February 27, 2026 22:20
@halter73 halter73 requested review from martincostello and wtgodbe and removed request for a team, Copilot and martincostello February 27, 2026 22:20
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reverts the stricter AcceptsMetadata/endpoint metadata behavior added for Microsoft.AspNetCore.JsonPatch (Newtonsoft.Json) so PATCH requests can again use Content-Type: application/json, while keeping Microsoft.AspNetCore.JsonPatch.SystemTextJson’s stricter behavior unchanged.

Changes:

  • Remove IEndpointParameterMetadataProvider/AcceptsMetadata population from Newtonsoft JsonPatchDocument types and drop the extra framework reference that made the package unusable for Blazor WASM.
  • Add end-to-end tests validating which Content-Type values are accepted for both Newtonsoft and System.Text.Json JsonPatch packages.
  • Update OpenAPI tests to verify Accepts(...)/[Consumes] can fully override the inferred JsonPatch request media type.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentService/OpenApiDocumentServiceTests.RequestBody.cs Tightens assertions to ensure inferred JsonPatch media types are fully overridden by explicit Accepts/Consumes.
src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj Adds required ASP.NET Core references for new end-to-end tests on .NET Core targets.
src/Features/JsonPatch/test/JsonPatchContentTypeEndToEndTest.cs New end-to-end coverage for accepted/rejected PATCH content types (Newtonsoft package).
src/Features/JsonPatch/src/Microsoft.AspNetCore.JsonPatch.csproj Removes framework reference that was introduced for endpoint metadata support (improves Blazor WASM compatibility).
src/Features/JsonPatch/src/JsonPatchDocumentOfT.cs Removes endpoint-parameter metadata provider implementation that enforced application/json-patch+json.
src/Features/JsonPatch/src/JsonPatchDocument.cs Removes endpoint-parameter metadata provider implementation that enforced application/json-patch+json.
src/Features/JsonPatch.SystemTextJson/test/Microsoft.AspNetCore.JsonPatch.SystemTextJson.Tests.csproj Adds required references for new end-to-end tests.
src/Features/JsonPatch.SystemTextJson/test/JsonPatchContentTypeEndToEndTest.cs New end-to-end coverage confirming stricter content-type behavior remains for SystemTextJson package.

@halter73 halter73 added feature-json-patch area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Feb 27, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume some sort of breaking change announcement is going to be made for this area?

Is there going to be a follow up discussion for blazor-wasm getting a non-newtonsoft json version?

@halter73
Copy link
Member Author

halter73 commented Feb 28, 2026

I assume some sort of breaking change announcement is going to be made for this area?

Maybe. I'm not sure how necessary it is given that we're reverting to the pre-.NET 10 behavior. It might just create more confusion. #65325 and #64330 should serve as notice of the unintentional breaking change until the next patch.

Is there going to be a follow up discussion for blazor-wasm getting a non-newtonsoft json version?

As far as I know, you simply cannot reference Microsoft.AspNetCore.Http.Abstractions from blazor-wasm either directly or indirectly (you wouldn't want Blazor WASM code referencing HttpContext after all). We may be able to #ifdef and multitarget for net11.0-browser though. I didn't want to do that for the patch since we had multiple reasons to revert the changes in the Newtonsoft JsonPatch package, but it could make sense to do that for the STJ package going forward in .NET 11. Assuming that's possible. Otherwise, it might be better to rip off the band aid and remove the Microsoft.AspNetCore.Http.Abstractions reference from the STJ package as well. I'm curious if @javiercn has any thoughts on this scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-json-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Breaking change: PATCH no longer accepts Content-Type application/json using JsonPatch packages not working in blazor-wasm

3 participants