-
Notifications
You must be signed in to change notification settings - Fork 114
Migrate LinuxScanner from Newtonsoft.Json to System.Text.Json
#1567
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
- `LinuxScanner`: - Replace `JsonConvert.SerializeObject` with `JsonSerializer.Serialize` - Replace `JsonConvert.DeserializeObject` with `SyftOutput.FromJson()` - Remove `Newtonsoft.Json` using directive - `SyftOutput`: - Regenerate from JSON schema using quicktype.io with `System.Text.Json` - Add `[JsonPropertyName]` attributes for proper property mapping - Add `[JsonIgnore]` attributes for null value handling - Add `FromJson()` helper method with case-insensitive parsing - Enable nullable reference types with appropriate pragmas - `LinuxScannerTests`: - Convert test JSON strings from escaped C# strings to raw literals - Fix property name casing to match schema (`versionID` vs `versionId`) - Remove trailing commas that were previously tolerated See #231
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1567 +/- ##
=======================================
- Coverage 90.1% 89.6% -0.6%
=======================================
Files 426 426
Lines 35975 36256 +281
Branches 2221 2260 +39
=======================================
+ Hits 32434 32494 +60
- Misses 3080 3300 +220
- Partials 461 462 +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 migrates the LinuxScanner component from Newtonsoft.Json to System.Text.Json, modernizing the JSON serialization approach. The changes include updating the LinuxScanner to use the new JSON APIs, regenerating the SyftOutput contract from the JSON schema with System.Text.Json attributes, and converting test JSON strings to use raw string literals while fixing property name casing.
Key changes:
- Replaced
JsonConvertmethods withJsonSerializerandSyftOutput.FromJson()in LinuxScanner - Regenerated
SyftOutputclass with[JsonPropertyName]and[JsonIgnore]attributes, nullable reference types, and custom converters - Converted test JSON strings to raw literals and corrected property name casing (mostly to
versionID)
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| LinuxScanner.cs | Updated JSON serialization/deserialization to use System.Text.Json APIs |
| SyftOutput.cs | Fully regenerated contract with System.Text.Json attributes, nullable support, and FromJson helper |
| LinuxScannerTests.cs | Converted test JSON to raw literals and updated property names to match schema |
src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SyftOutput.cs
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SyftOutput.cs
Show resolved
Hide resolved
src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SyftOutput.cs
Show resolved
Hide resolved
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
LinuxScanner:JsonConvert.SerializeObjectwithJsonSerializer.SerializeJsonConvert.DeserializeObjectwithSyftOutput.FromJson()Newtonsoft.Jsonusing directiveSyftOutput:System.Text.Json[JsonPropertyName]attributes for proper property mapping[JsonIgnore]attributes for null value handlingFromJson()helper method with case-insensitive parsingLinuxScannerTests:versionIDvsversionId)See #231