Complete migration from Newtonsoft.Json to System.Text.Json#1610
Open
JamieMagee wants to merge 4 commits intomainfrom
Open
Complete migration from Newtonsoft.Json to System.Text.Json#1610JamieMagee wants to merge 4 commits intomainfrom
Newtonsoft.Json to System.Text.Json#1610JamieMagee wants to merge 4 commits intomainfrom
Conversation
The TypedComponent base class was using dual attributes for both Newtonsoft.Json and System.Text.Json serialization. Since polymorphic serialization is now handled by [JsonPolymorphic] and [JsonDerivedType] attributes from System.Text.Json, the Newtonsoft.Json attributes are no longer needed. Changes: - Remove Newtonsoft.Json, Newtonsoft.Json.Converters, and Newtonsoft.Json.Serialization using directives - Remove [JsonObject] and [JsonConverter(typeof(TypedComponentConverter))] class attributes - Remove duplicate [JsonIgnore] and [JsonProperty] attributes - Keep only System.Text.Json [JsonPropertyName] and [JsonIgnore] attributes - Remove reference to TypedComponentConverter (will be deleted separately)
Update BcdeModels classes to use only System.Text.Json serialization attributes. The [JsonObject] attributes with CamelCaseNamingStrategy were used for Newtonsoft.Json but are not needed since all properties already have explicit [JsonPropertyName] attributes. Changes: - ScanResult.cs: Remove [JsonObject], replace StringEnumConverter with JsonStringEnumConverter for ResultCode property - ScannedComponent.cs: Remove [JsonObject], replace StringEnumConverter with JsonStringEnumConverter for DependencyScope property - Detector.cs: Remove [JsonObject] and [JsonProperty(ItemConverterType)] (ComponentType enum already has [JsonStringEnumConverter] at type level) - ContainerDetails.cs: Remove [JsonObject] and Newtonsoft usings - DefaultGraphScanResult.cs: Remove [JsonObject] and Newtonsoft usings - DependencyGraphWithMetadata.cs: Remove [JsonObject] and Newtonsoft usings
The TypedComponentConverter was a Newtonsoft.Json JsonConverter that handled polymorphic deserialization of TypedComponent subclasses by reading the 'type' discriminator property. This converter is no longer needed because System.Text.Json polymorphic serialization is now handled by the [JsonPolymorphic] and [JsonDerivedType] attributes on the TypedComponent base class, which were added in a previous migration step.
Remove the Newtonsoft.Json package reference from the following projects now that all serialization code has been migrated to System.Text.Json: - Microsoft.ComponentDetection.Contracts.csproj - Microsoft.ComponentDetection.Detectors.csproj - Microsoft.ComponentDetection.Orchestrator.csproj Note: Newtonsoft.Json remains in Directory.Packages.props because it is still needed as a transitive dependency of Newtonsoft.Json.Schema, which is used in the verification tests for JSON schema validation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1610 +/- ##
=====================================
Coverage 90.1% 90.2%
=====================================
Files 437 436 -1
Lines 37431 37395 -36
Branches 2316 2316
=====================================
- Hits 33736 33735 -1
+ Misses 3221 3185 -36
- Partials 474 475 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR completes the migration from Newtonsoft.Json to System.Text.Json by removing dual serialization attributes that were maintained for backward compatibility. All production code already uses System.Text.Json exclusively.
Changes:
- Removed all
Newtonsoft.Jsonpackage references from Contracts, Detectors, and Orchestrator projects - Cleaned up duplicate JSON serialization attributes in
TypedComponentandBcdeModelsclasses - Deleted the obsolete
TypedComponentConverterclass that was only needed for Newtonsoft.Json
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Microsoft.ComponentDetection.Contracts.csproj | Removed Newtonsoft.Json package reference |
| Microsoft.ComponentDetection.Detectors.csproj | Removed Newtonsoft.Json package reference |
| Microsoft.ComponentDetection.Orchestrator.csproj | Removed Newtonsoft.Json package reference |
| TypedComponent.cs | Removed Newtonsoft.Json using statements, attributes, and duplicate JsonIgnore declarations; kept System.Text.Json attributes |
| TypedComponentConverter.cs | Deleted obsolete converter (polymorphism now handled by JsonPolymorphic attribute) |
| ScannedComponent.cs | Removed JsonObject attribute and Newtonsoft usings; updated enum converter to JsonStringEnumConverter |
| ScanResult.cs | Removed JsonObject attribute and Newtonsoft usings; updated enum converter to JsonStringEnumConverter |
| Detector.cs | Removed JsonObject attribute, Newtonsoft usings, and ItemConverterType (ComponentType enum has type-level converter) |
| DependencyGraphWithMetadata.cs | Removed JsonObject attribute and Newtonsoft usings |
| DefaultGraphScanResult.cs | Removed JsonObject attribute and Newtonsoft usings |
| ContainerDetails.cs | Removed JsonObject attribute and Newtonsoft usings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR completes the migration from
Newtonsoft.JsontoSystem.Text.Jsonfor theBcdeModelsandTypedComponentserialization. The codebase was previously using dual attributes to support both serializers, but all production code already usesSystem.Text.Jsonexclusively.TypedComponentNewtonsoft.Jsonattributes ([JsonObject],[JsonConverter],[JsonProperty])[JsonIgnore]attributes (kept onlySystem.Text.Jsonversions)[JsonPolymorphic]and[JsonDerivedType]attributesBcdeModels[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))]from all classesNewtonsoft.Json.Converters.StringEnumConverterwithSystem.Text.Json.Serialization.JsonStringEnumConverterfor enum propertiesTypedComponentConverter(no longer needed - polymorphism handled by[JsonPolymorphic])Newtonsoft.Jsonfrom:Microsoft.ComponentDetection.Contracts.csprojMicrosoft.ComponentDetection.Detectors.csprojMicrosoft.ComponentDetection.Orchestrator.csproj