Unions and closed types - #404
Merged
Merged
Conversation
Unions are a new runtime shape Argon did not understand: a union serialized
to the wrapper {"Value":42} and could not be deserialized at all. UnionConverter
now writes the bare active case with no wrapper and no discriminator, matching
System.Text.Json. Reading picks the case from the JSON value shape, and falls
back to comparing property names when several cases serialize as objects.
It ships as a built in converter, so the serializer core is untouched.
Closed hierarchies already round tripped through TypeNameHandling and a binder,
but only with assembly qualified names and manual setup. The new opt in
JsonSerializerSettings.InferClosedTypePolymorphism uses the derived types the
compiler records on the base to write and read a short $type discriminator,
with no binder required. Because the candidate set is fixed at compile time an
incoming discriminator can never name an arbitrary type, so the usual
TypeNameHandling warning about untrusted input does not apply.
Both compiler markers are matched by attribute full name rather than through a
type reference. Their definitions come from the target framework on net11 and
from a polyfill below it, and a polyfilled copy is internal to each assembly,
so Argon's own copy would never match a consumer's. This also means one code
path covers net462 through net11.0 with no conditional compilation.
PolyNullability is enabled because case nullability decides which case accepts
a null payload, and Polyfill gates NullabilityInfoContext behind that property.
The declared type computation in ShouldWriteType is extracted so the writer
hooks can reuse it; that refactor is behaviour preserving.
ArgonTests overrides Verify to 33.0.0-beta.8 while central package management pins 32.0.0. Argon.FSharp.Tests and Benchmark.Tests reference ArgonTests, so they saw the prerelease transitively alongside the centrally pinned 32.0.0 and failed to restore with NU1109. Matching the override in both makes the whole solution build and test again.
This was referenced Sep 11, 2026
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.
No description provided.