Fix STJ migration: thread safety, collection element default-value serialization, and IsVisible roundtrip#9358
Closed
Copilot wants to merge 5 commits intouser/philnach/NewtonSoftTransitivefrom
Closed
Conversation
Co-authored-by: philnach <19275540+philnach@users.noreply.github.com>
… XML warning Co-authored-by: philnach <19275540+philnach@users.noreply.github.com>
Co-authored-by: philnach <19275540+philnach@users.noreply.github.com>
… .gitignore Co-authored-by: philnach <19275540+philnach@users.noreply.github.com>
Contributor
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Copilot
AI
changed the title
[WIP] Migrate AdaptiveCards .NET library from Newtonsoft.Json to System.Text.Json
Fix STJ migration: thread safety, collection element default-value serialization, and IsVisible roundtrip
Mar 6, 2026
Copilot AI
added a commit
that referenced
this pull request
Mar 6, 2026
…efaults, IsVisible roundtrip Co-authored-by: philnach <19275540+philnach@users.noreply.github.com>
Member
|
this was merged into #9357 |
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.
Three bugs introduced by the Newtonsoft.Json → System.Text.Json migration, found during code review.
Description
1. Thread-safety:
AdaptiveFallbackConverter.IsInFallback(AdaptiveFallbackConverter.cs)static bool IsInFallbackwas shared across threads. Concurrent parses could corrupt the fallback flag read byParseContext.PushElement, causing false ID-collision exceptions or silently suppressing real ones. Fixed with a[ThreadStatic]backing field.2. Collection element default-value leakage (
AdaptiveCollectionElementConverterFactory.cs)AdaptiveCollectionElementConverter.Writehand-walks properties via reflection but only checked[JsonIgnore(Condition = Always)]. It ignored per-propertyWhenWritingNull/WhenWritingDefaultconditions entirely, soContainer,Column,ColumnSet,Table, andTableCellemitted noise like"separator": false,"bleed": false,"horizontalAlignment": "Left", and"verticalContentAlignment": null(the last becauseIgnoreDefaultStringEnumConverter.Writeemitsnullfor enum defaults). Fixed by reading each property'sJsonIgnoreAttribute.Conditionbefore writing, falling back tooptions.DefaultIgnoreCondition.3.
IsVisible = falseroundtrip regression (AdaptiveElement.cs)The mechanical migration translated
[DefaultValue(true)]+DefaultValueHandling.IgnoreAndPopulateto[JsonIgnore(Condition = WhenWritingDefault)]. STJ'sWhenWritingDefaultskips aboolwhen it equalsdefault(bool)=false— the opposite of the intent. Result: serializingIsVisible = falseproduced noisVisiblefield; parsing back silently restoredIsVisible = true, making hidden elements reappear. Fixed by removing the incorrectWhenWritingDefaultcondition. STJ now always serializesisVisible(a known, accepted breaking change;"isVisible": truewill appear in output where it was previously omitted).Also fixed: unresolvable
crefXML doc warning inSafeJsonHelper.cs.Sample Card
No new sample card needed; existing cards in
samples/exercise all affected element types.How Verified
New regression tests in
SystemTextJsonMigrationTests:ConcurrentFallbackParsing_IsThreadSafe— 10 threads × 50 iterations parsing cards with same-ID fallback elementsCollectionElements_DefaultPropertiesAreNotSerialized— assertsseparator,bleed,horizontalAlignment,verticalContentAlignmentabsent for default-valued containers; asserts non-default values still round-tripIsVisible_False_RoundtripsCorrectly— serializesTextBlockandContainerwithIsVisible = false, asserts the field is present in JSON and the value survives parseAll existing tests pass (166 pass; 3 failures are environment-only
DirectoryNotFoundExceptionfor missingsamples/paths, pre-existing before this PR).🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.