Skip to content

Convert Razor tools from NewtonSoft.Json to System.Text.Json#53345

Merged
davidwengier merged 6 commits into
dotnet:mainfrom
davidwengier:SystemTextJson
Mar 12, 2026
Merged

Convert Razor tools from NewtonSoft.Json to System.Text.Json#53345
davidwengier merged 6 commits into
dotnet:mainfrom
davidwengier:SystemTextJson

Conversation

@davidwengier

Copy link
Copy Markdown
Member

Part of #53287

@github-actions github-actions Bot added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK label Mar 10, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @@davidwengier.
To learn about the PR process and branching schedule of this repo, please take a look at the SDK PR Guide.

@davidwengier davidwengier marked this pull request as ready for review March 10, 2026 05:29
@davidwengier davidwengier requested a review from a team as a code owner March 10, 2026 05:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Migrates the Razor SDK tool’s TagHelper manifest JSON serialization/deserialization from Newtonsoft.Json to System.Text.Json to help remove Newtonsoft.Json from the SDK layout (per #53287).

Changes:

  • Replace Newtonsoft-based JSON read/write pipeline with System.Text.Json equivalents (custom converter + reader/writer abstractions).
  • Remove the Newtonsoft.Json package reference from the Razor tool project.
  • Add round-trip serialization tests for TagHelperDescriptor JSON payloads.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/Microsoft.NET.Sdk.Razor.Tool.Tests/TagHelperJsonSerializationTest.cs Adds comprehensive round-trip tests validating TagHelperDescriptor JSON compatibility.
src/RazorSdk/Tool/Microsoft.NET.Sdk.Razor.Tool.csproj Removes Newtonsoft.Json package dependency from the tool.
src/RazorSdk/Tool/Json/TagHelperDescriptorJsonConverter.cs Introduces shared JsonSerializerOptions for the custom converter.
src/RazorSdk/Tool/Json/Strings.cs Replaces Newtonsoft token types with System.Text.Json token types.
src/RazorSdk/Tool/Json/ObjectWriters_TagHelpers.cs Removes now-unneeded helper method overload(s) after writer changes.
src/RazorSdk/Tool/Json/ObjectWriters.cs Removes now-unneeded RazorExtension JSON writer helpers.
src/RazorSdk/Tool/Json/ObjectReaders_TagHelpers.cs Removes now-unneeded TagHelperDescriptor wrapper reader helper.
src/RazorSdk/Tool/Json/ObjectJsonConverter`1.cs Reimplements converter using System.Text.Json reader/writer APIs.
src/RazorSdk/Tool/Json/JsonReaderExtensions.cs Deletes Newtonsoft.Json reader extension utilities.
src/RazorSdk/Tool/Json/JsonDataWriter.cs Replaces JsonWriter-based writer with Utf8JsonWriter-based implementation and prunes unused APIs.
src/RazorSdk/Tool/Json/JsonDataReader.cs Replaces JsonReader-based reader with JsonElement-based implementation and prunes unused APIs.
src/RazorSdk/Tool/GenerateCommand.cs Switches manifest deserialization to System.Text.Json with shared options.
src/RazorSdk/Tool/DiscoverCommand.cs Switches manifest serialization to System.Text.Json with shared options.

Comment thread src/RazorSdk/Tool/Json/JsonDataReader.cs
Comment thread src/RazorSdk/Tool/Json/ObjectJsonConverter`1.cs

@DustinCampbell DustinCampbell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, though it might be nice to have a test that verifies round-tripping the current output of the discover command.

davidwengier added a commit to dotnet/razor that referenced this pull request Mar 11, 2026
Sorry, I promised Todd I wouldn't remove any more big swathes of code,
but when [converting the SDK](dotnet/sdk#53345)
to use System.Text.Json I discovered that none of the serialization code
in this repo is actually used there, and so it was a case of either
leave this code to be unused, and not matching the SDK, or convert
unused code, or just get rid of it. So I got rid of it.

Arguably some of this is bits I missed in the last PR anyway (in that PR
I removed ProjectSnapshotHandle from being used, but left the code that
knew how to serialize it 🤷‍♂️)
@davidwengier davidwengier merged commit 7d19864 into dotnet:main Mar 12, 2026
27 checks passed
@Frulfump

Copy link
Copy Markdown

Great work!

Title and description should have mentioned it was only for Razor imo.

@davidwengier davidwengier changed the title Convert from NewtonSoft.Json to System.Text.Json Convert Razor tools from NewtonSoft.Json to System.Text.Json Mar 12, 2026
@davidwengier

Copy link
Copy Markdown
Member Author

Good point!

davidwengier added a commit to dotnet/roslyn that referenced this pull request Apr 28, 2026
Sorry, I promised Todd I wouldn't remove any more big swathes of code,
but when [converting the SDK](dotnet/sdk#53345)
to use System.Text.Json I discovered that none of the serialization code
in this repo is actually used there, and so it was a case of either
leave this code to be unused, and not matching the SDK, or convert
unused code, or just get rid of it. So I got rid of it.

Arguably some of this is bits I missed in the last PR anyway (in that PR
I removed ProjectSnapshotHandle from being used, but left the code that
knew how to serialize it 🤷‍♂️)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants