Repository navigation
fix: read a wrapper set's JSON element tokens as its primitive set reads them - #164
Merged
Merged
Conversation
…ads them
The wrapper element converters handed a JSON string token to the
family's array-literal grammar unconditionally, while the primitive
sets read their elements with System.Text.Json's own converters. So
Int32Set<OrderId> read ["7"], [" 7 "] and ["+7"] under any options
where Int32Set threw JsonException, and GuidSet<TenantId> read braces
and the undashed form where GuidSet threw. Swapping the arity changed
what an endpoint accepted, contrary to docs/serialization.md ("byte
for byte the same").
ValueSetElementJson now reads an integer or decimal string token only
under JsonNumberHandling.AllowReadingFromString, with the grammar
System.Text.Json reads inside the quotes (a sign and digits; sign,
digits, point and exponent; never whitespace), and the integer and
decimal converters route through it. ValueSetGuidElementJsonConverter
reads a wrapper Guid with Utf8JsonReader.GetGuid — the hyphenated form
only — and hands the family its D text, so the element's validation
still runs. WriteAsString alone no longer round-trips a wrapper set,
as it never did a plain one. WrapperGrammarContractTests holds a JSON
string to the primitive set's JSON read rather than to the literal.
Closes #141
Found-By: OT
Defect-Class: JSON
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ated form at the JSON write The Guid element converter reads the hyphenated form only, as System.Text.Json reads a Guid, but wrote whatever the element formatted as. A wrapper formatting as N passes the literal, which uuid_in reads, and the EF Core bridge, which parses it the same way, and then wrote ["6f9619ff8b86d011b42d00c04fc964ff"], which neither GuidSet nor the wrapper reads back. The write refuses it naming the text-form contract, as the integer converter refuses non-numeric text. Found by the value-semantics review of the 10.0.0 element-grammar branch. Found-By: RV Defect-Class: JSON Co-Authored-By: Claude Fable 5.1 <[email protected]>
CaffeinatedCoder
force-pushed
the
fix/wrapper-json-element-tokens
branch
from
October 18, 2026 12:49
fee2f5b to
2239cc7
Compare
This was referenced Oct 18, 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.
Closes #141
Stacked on #163 (
fix/string-set-nul), which is stacked on #162; the diff againstmainincludes both until they merge.Problem
docs/serialization.mdpromises thatInt32Set<OrderId>andInt32Setare "byte for byte the same". On write that held; on read the wrapper's element converters handed a JSON string token to the family's array-literal grammar unconditionally, while the primitive set reads its elements with System.Text.Json's own converter. So with the default optionsInt32Set<OrderId>read["7"],[" 7 "]and["+7"]whereInt32SetthrewJsonException,DecimalSet<T>and the other integer arities likewise, andGuidSet<TenantId>read["{6f9619ff-…}"]and the undashed form whereGuidSetthrew. Swapping the arity changed what an endpoint accepted.Change
ValueSetElementJsonConverter.cs:ValueSetElementJson.ReadIntegerText/ReadDecimalTextread a number token as before and a string token only underJsonNumberHandling.AllowReadingFromString, with the grammar System.Text.Json reads inside the quotes (verified againstUtf8Parser: an optional sign and digits for an integer; sign, digits, point and exponent for a decimal; never whitespace). The integer and decimal converters route through them. NewValueSetGuidElementJsonConverter<TSet, T>reads a wrapper Guid withUtf8JsonReader.GetGuid(the hyphenated form only, either case) and hands the family itsDtext, so the element'sParsestill runs;GuidSet<T>names it.WriteAsStringalone no longer round-trips a wrapper set, as it never did a plain one (SetJsonConverterTestsasserts that for both siblings, and the round trip underWriteAsString | AllowReadingFromString).WrapperGrammarContractTests: the JSON-string leg is held to the primitive set's JSON read (under the default options and underAllowReadingFromString) instead of to the literal, which was the assumption Wrapper set arities read JSON element tokens their primitive set refuses (quoted, padded, signed numbers; braced and unhyphenated Guids) #141 names.test/oracles/candidates.json: the four numeric rows of Wrapper set arities read JSON element tokens their primitive set refuses (quoted, padded, signed numbers; braced and unhyphenated Guids) #141 are removed (the Guid row went with fix: read GuidSet elements with PostgreSQL's uuid_in grammar #162).clone-waivers.json: theDecimalSet<T>.ElementJsonConverterwaiver is gone, since the Guid arity now names a converter of its own too.Docs:
docs/value-sets.md#how-your-element-types-sort-and-serialize(what a wrapper reads, and what 9.x read),docs/serialization.md#element-converters, claimJ29-wrapper-reads-what-the-primitive-reads, the 10.0.0 Breaking row, and "Send a wrapper set the JSON you send the plain set" indocs/migration.md.Second commit, from the value-semantics review of the whole stack: the Guid converter also refuses, at the write, an element that formats without hyphens (
N,B,P). Such an element passes the literal (uuid_inreads it) and the EF bridge, and then wrote["6f9619ff8b86d011b42d00c04fc964ff"], which neitherGuidSetnor the wrapper reads back; now it throwsJsonExceptionnaming the text-form contract, as the integer converter does for non-numeric text (WrapperSet_GuidBacked_ElementNotFormattingAsTheHyphenatedForm_IsRefusedOnWrite, proven by reverting the check).Tests
SetJsonConverterTests:WrapperSet_IntegerBacked_ReadsEachTokenAsItsPrimitiveDoes(12 tokens × 2 option sets ×Int32Set/Int16Setpairs),WrapperSet_DecimalBacked_ReadsEachTokenAsItsPrimitiveDoes(11 tokens × 2),WrapperSet_GuidBacked_ReadsEachTokenAsItsPrimitiveDoes(9 tokens),WrapperSet_IntegerBacked_ReadsNumbersWrittenAsStrings_OnlyWhenTheOptionsAllowIt,WrapperSet_NumericBacked_RoundTripsUnderWriteAsString_ExactlyAsItsPrimitiveDoes.SetWrapperParityTestsholds its four numeric rows;WrapperGrammarContractTestsJSON leg;JsonOptionsProbeTestsunderAllowReadingFromStringunchanged and green.ValueSetElementJsonConverter.csandGuidSet.csfrom the parent commit, tests kept): 17 rows ofSetJsonConverterTestsfail (decimal, Guid and integer tokens), andWrapperGrammarContractTestsreportsDecimalSet<LenientAmount> JSON string under default options of {"1.5"}: {1.5}, but DecimalSet reads refusedand its siblings. Restored afterwards.🤖 Generated with Claude Code