Skip to content

Revert media type change for Newtonsoft JsonPatch package#65559

Merged
halter73 merged 5 commits intomainfrom
halter73/65325
Mar 5, 2026
Merged

Revert media type change for Newtonsoft JsonPatch package#65559
halter73 merged 5 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.

@halter73 halter73 enabled auto-merge (squash) March 4, 2026 19:38
@halter73 halter73 disabled auto-merge March 4, 2026 19:40
@halter73 halter73 enabled auto-merge (squash) March 4, 2026 19:55
@halter73 halter73 enabled auto-merge (squash) March 4, 2026 19:55
@halter73
Copy link
Member Author

halter73 commented Mar 5, 2026

/ba-g It appears only quarantined tests unrelated to the PR are failing.

@halter73 halter73 merged commit 4e3592e into main Mar 5, 2026
23 of 25 checks passed
@halter73 halter73 deleted the halter73/65325 branch March 5, 2026 19:24
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview3 milestone Mar 5, 2026
@halter73
Copy link
Member Author

halter73 commented Mar 6, 2026

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Started backporting to release/10.0 (link to workflow run)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

@halter73 backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Revert media type change for Newtonsoft JsonPatch package
Using index info to reconstruct a base tree...
M	src/Features/JsonPatch.SystemTextJson/test/Microsoft.AspNetCore.JsonPatch.SystemTextJson.Tests.csproj
M	src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj
Falling back to patching base and 3-way merge...
Auto-merging src/Features/JsonPatch.SystemTextJson/test/Microsoft.AspNetCore.JsonPatch.SystemTextJson.Tests.csproj
CONFLICT (content): Merge conflict in src/Features/JsonPatch.SystemTextJson/test/Microsoft.AspNetCore.JsonPatch.SystemTextJson.Tests.csproj
Auto-merging src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj
CONFLICT (content): Merge conflict in src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Revert media type change for Newtonsoft JsonPatch package
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

Copilot AI added a commit that referenced this pull request Mar 6, 2026
…onPatchDocument types

- Remove IEndpointParameterMetadataProvider implementation from JsonPatchDocument and JsonPatchDocument<T>
- Remove Microsoft.AspNetCore.Http.Abstractions reference from JsonPatch.csproj
- Add end-to-end content type tests for both Newtonsoft and SystemTextJson JsonPatch
- Update test csproj files with required references (resolving merge conflicts)
- Add DoesNotContain assertions to OpenApi tests for custom content types

Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
wtgodbe pushed a commit that referenced this pull request Mar 6, 2026
…t JsonPatchDocument (#65674)

* Initial plan

* Backport PR #65559: Remove IEndpointParameterMetadataProvider from JsonPatchDocument types

- Remove IEndpointParameterMetadataProvider implementation from JsonPatchDocument and JsonPatchDocument<T>
- Remove Microsoft.AspNetCore.Http.Abstractions reference from JsonPatch.csproj
- Add end-to-end content type tests for both Newtonsoft and SystemTextJson JsonPatch
- Update test csproj files with required references (resolving merge conflicts)
- Add DoesNotContain assertions to OpenApi tests for custom content types

Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Co-authored-by: Stephen Halter <halter73@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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

4 participants