-
Notifications
You must be signed in to change notification settings - Fork 114
Complete migration from Newtonsoft.Json to System.Text.Json
#1610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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