Skip to content

Complete migration from Newtonsoft.Json to System.Text.Json#1610

Open
JamieMagee wants to merge 7 commits into
mainfrom
user/jamagee/migrate-to-system-text-json
Open

Complete migration from Newtonsoft.Json to System.Text.Json#1610
JamieMagee wants to merge 7 commits into
mainfrom
user/jamagee/migrate-to-system-text-json

Conversation

@JamieMagee

Copy link
Copy Markdown
Member

This PR completes the migration from Newtonsoft.Json to System.Text.Json for the BcdeModels and TypedComponent serialization. The codebase was previously using dual attributes to support both serializers, but all production code already uses System.Text.Json exclusively.

  • Changes
    • TypedComponent
      • Removed Newtonsoft.Json attributes ([JsonObject], [JsonConverter], [JsonProperty])
      • Removed duplicate [JsonIgnore] attributes (kept only System.Text.Json versions)
      • Polymorphic serialization continues to work via existing [JsonPolymorphic] and [JsonDerivedType] attributes
  • BcdeModels
    • Removed [JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] from all classes
    • Replaced Newtonsoft.Json.Converters.StringEnumConverter with System.Text.Json.Serialization.JsonStringEnumConverter for enum properties
    • Deleted TypedComponentConverter (no longer needed - polymorphism handled by [JsonPolymorphic])
  • Package References
    • Removed Newtonsoft.Json from:
      • Microsoft.ComponentDetection.Contracts.csproj
      • Microsoft.ComponentDetection.Detectors.csproj
      • Microsoft.ComponentDetection.Orchestrator.csproj

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

codecov Bot commented Jan 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.2%. Comparing base (2ed2e3b) to head (bcde0d4).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

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.Json package references from Contracts, Detectors, and Orchestrator projects
  • Cleaned up duplicate JSON serialization attributes in TypedComponent and BcdeModels classes
  • Deleted the obsolete TypedComponentConverter class 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

Copilot AI review requested due to automatic review settings July 10, 2026 17:42
@github-actions

Copy link
Copy Markdown

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

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.

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 0 new
  • Review effort level: Low

Copilot AI review requested due to automatic review settings July 10, 2026 18:07

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.

Review details

  • Files reviewed: 14/14 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment on lines 12 to 14
[DebuggerDisplay("{DebuggerDisplay,nq}")]
[SystemTextJson.JsonConverter(typeof(TypedComponentSystemTextJsonConverter))] // System.Text.Json
[JsonConverter(typeof(TypedComponentSystemTextJsonConverter))]
public abstract class TypedComponent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants