Skip to content

Conversation

@JamieMagee
Copy link
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
Copy link

codecov bot commented Jan 12, 2026

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.

Copy link

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

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

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.

2 participants