-
Notifications
You must be signed in to change notification settings - Fork 113
Migrate some tests from Newtonsoft.Json to System.Text.Json
#1523
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
Conversation
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
222fb36 to
ac777b6
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1523 +/- ##
=====================================
Coverage 90.2% 90.2%
=====================================
Files 426 426
Lines 35965 35965
Branches 2216 2216
=====================================
+ Hits 32464 32465 +1
Misses 3045 3045
+ Partials 456 455 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ac777b6 to
633f0ab
Compare
633f0ab to
406cdf8
Compare
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 migrates test code from Newtonsoft.Json to System.Text.Json as part of issue #231. The migration maintains backward compatibility by adding dual serialization attributes to shared contract classes, allowing production code to continue using Newtonsoft.Json while tests use System.Text.Json.
Key Changes
- Replaced
JsonConvert.Serialize/DeserializewithJsonSerializer.Serialize/Deserializein test files - Added
System.Text.Json.Serializationattributes alongside existingNewtonsoft.Jsonattributes in pip contract classes - Fixed a comment in
PyPiClientTests.csto accurately reflect that an API call is made twice instead of once
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.VerificationTests/ComponentDetectionIntegrationTests.cs | Updated serialization calls and imports for integration tests |
| test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs | Migrated telemetry deserialization to System.Text.Json |
| test/Microsoft.ComponentDetection.Detectors.Tests/YarnLockDetectorTests.cs | Updated workspace JSON serialization in yarn lock tests |
| test/Microsoft.ComponentDetection.Detectors.Tests/SimplePypiClientTests.cs | Migrated PyPI project serialization in simple client tests |
| test/Microsoft.ComponentDetection.Detectors.Tests/SimplePipComponentDetectorTests.cs | Updated dependency graph serialization for error messages |
| test/Microsoft.ComponentDetection.Detectors.Tests/PyPiClientTests.cs | Migrated PyPI client tests and fixed comment accuracy |
| test/Microsoft.ComponentDetection.Detectors.Tests/PipReportComponentDetectorTests.cs | Updated pip report deserialization in detector tests |
| src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipInstallationReportItem.cs | Added System.Text.Json attributes while maintaining Newtonsoft.Json compatibility |
| src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipInstallationReport.cs | Added dual serialization attributes for transitional compatibility |
| src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipInstallationMetadata.cs | Added System.Text.Json property name attributes alongside existing ones |
30146db to
a009fc8
Compare
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
Copilot reviewed 17 out of 17 changed files in this pull request and generated 8 comments.
test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScannedComponent.cs
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.VerificationTests/ComponentDetectionIntegrationTests.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipInstallationReportItem.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipInstallationReportItem.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.VerificationTests/ComponentDetectionIntegrationTests.cs
Outdated
Show resolved
Hide resolved
9978965 to
b6e6d8a
Compare
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
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipInstallationReportItem.cs
Outdated
Show resolved
Hide resolved
b6e6d8a to
3024c78
Compare
3024c78 to
5f82a37
Compare
5f82a37 to
4bc88cc
Compare
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
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
test/Microsoft.ComponentDetection.VerificationTests/ComponentDetectionIntegrationTests.cs
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.Detectors.Tests/SimplePipComponentDetectorTests.cs
Show resolved
Hide resolved
4bc88cc to
b0daa3d
Compare
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
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
41b41e0 to
54ba4b8
Compare
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
Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.
test/Microsoft.ComponentDetection.VerificationTests/ComponentDetectionIntegrationTests.cs
Show resolved
Hide resolved
test/Microsoft.ComponentDetection.VerificationTests/ComponentDetectionIntegrationTests.cs
Show resolved
Hide resolved
…ext.Json` In #1523 we added the `[JsonProperty(Order = int.MinValue]` `Newtonsoft.Json` attribute to the `Type` property of the `TypedComponent` class to ensure that `"type"` would appear first in the serialized object. This is because `System.Text.Json` requires the type discriminator to be the first property of the object[^1]. `System.Text.Json` `9.0.0` and later does support the `JsonSerializerOptions.AllowOutOfOrder` option[^2], but as we're targeting .NET 8, we don't have access to that. [^1]: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism#polymorphic-type-discriminators [^2]: https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions.allowoutofordermetadataproperties?view=net-10.0#system-text-json-jsonserializeroptions-allowoutofordermetadataproperties
…ext.Json` (#1558) In #1523 we added the `[JsonProperty(Order = int.MinValue]` `Newtonsoft.Json` attribute to the `Type` property of the `TypedComponent` class to ensure that `"type"` would appear first in the serialized object. This is because `System.Text.Json` requires the type discriminator to be the first property of the object[^1]. `System.Text.Json` `9.0.0` and later does support the `JsonSerializerOptions.AllowOutOfOrder` option[^2], but as we're targeting .NET 8, we don't have access to that. [^1]: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism#polymorphic-type-discriminators [^2]: https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions.allowoutofordermetadataproperties?view=net-10.0#system-text-json-jsonserializeroptions-allowoutofordermetadataproperties
This pull request contains the following changes:
Newtonsoft.Json.JsonConverttoSystem.Text.Json.JsonSerializerPipInstallationReportfromNewtonsoft.JsontoSystem.Text.JsonJObjectandJArrayproperties directly which cannot be handled bySystem.Text.JsonTypedComponenthierarchypublicinstead ofprivateorinternalPart of #231