Fix JSON serialization for Result-derived classes#642
Open
felickz wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix JSON serialization for Result-derived classes#642felickz wants to merge 1 commit intomicrosoft:mainfrom
felickz wants to merge 1 commit intomicrosoft:mainfrom
Conversation
* Initial plan * Initial investigation of exporttags JSON bug Co-authored-by: felickz <1760475+felickz@users.noreply.github.com> * Fix exporttags JSON output bug by using runtime type for serialization Co-authored-by: felickz <1760475+felickz@users.noreply.github.com> * Improve test to exercise actual JsonWriter code path - Modified ExportJsonSerialization test to use JsonWriter.WriteResults - Added InternalsVisibleTo attribute to expose JsonWriter to tests - Test now validates production code path instead of direct serialization Co-authored-by: felickz <1760475+felickz@users.noreply.github.com> * Revert nuget.config to use Azure DevOps feed Per repo guidance, nuget.config changes should not be checked in. Reverting to original Azure DevOps feed configuration. Co-authored-by: felickz <1760475+felickz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a JSON serialization bug in the exporttags command where only the appVersion field was being output instead of all tag data. The root cause was that JsonSerializer.Serialize was using the compile-time base type (Result) instead of the runtime derived type, causing only base class properties to be serialized.
Changes:
- Fixed JSON serialization to use runtime type (
result.GetType()) for Result-derived classes (TagDiffResult, ExportTagsResult, VerifyRulesResult) - Added comprehensive test that exercises the actual JsonWriter production code path
- Added InternalsVisibleTo attribute to enable testing internal CLI components
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| AppInspector.CLI/Writers/JsonWriter.cs | Fixed serialization to pass runtime type parameter, ensuring derived class properties are included in JSON output |
| AppInspector.Tests/Commands/TestExportTagsCmd.cs | Added test that validates JSON serialization through production JsonWriter code path |
| AppInspector.CLI/Properties/AssemblyInfo.cs | Added InternalsVisibleTo attribute to expose internal JsonWriter class to test project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix exporttags JSON output bug by using runtime type for serialization
Improve test to exercise actual JsonWriter code path
Fixes: Bug:
exporttagswith--output-file-format jsonoutputs only appVersion, no tags #641