Skip to content

fix: read a wrapper set's JSON element tokens as its primitive set reads them - #164

Merged
CaffeinatedCoder merged 3 commits into
mainfrom
fix/wrapper-json-element-tokens
Oct 18, 2026
Merged

CaffeinatedCoder merged 3 commits into
mainfrom
fix/wrapper-json-element-tokens

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Closes #141

Stacked on #163 (fix/string-set-nul), which is stacked on #162; the diff against main includes both until they merge.

Problem

docs/serialization.md promises that Int32Set<OrderId> and Int32Set are "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 options Int32Set<OrderId> read ["7"], [" 7 "] and ["+7"] where Int32Set threw JsonException, DecimalSet<T> and the other integer arities likewise, and GuidSet<TenantId> read ["{6f9619ff-…}"] and the undashed form where GuidSet threw. Swapping the arity changed what an endpoint accepted.

Change

  • ValueSetElementJsonConverter.cs: ValueSetElementJson.ReadIntegerText / ReadDecimalText read a number token as before and a string token only under JsonNumberHandling.AllowReadingFromString, with the grammar System.Text.Json reads inside the quotes (verified against Utf8Parser: 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. New ValueSetGuidElementJsonConverter<TSet, T> reads a wrapper Guid with Utf8JsonReader.GetGuid (the hyphenated form only, either case) and hands the family its D text, so the element's Parse still runs; GuidSet<T> names it.

  • WriteAsString alone no longer round-trips a wrapper set, as it never did a plain one (SetJsonConverterTests asserts that for both siblings, and the round trip under WriteAsString | AllowReadingFromString).

  • WrapperGrammarContractTests: the JSON-string leg is held to the primitive set's JSON read (under the default options and under AllowReadingFromString) 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: the DecimalSet<T>.ElementJsonConverter waiver 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, claim J29-wrapper-reads-what-the-primitive-reads, the 10.0.0 Breaking row, and "Send a wrapper set the JSON you send the plain set" in docs/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_in reads it) and the EF bridge, and then wrote ["6f9619ff8b86d011b42d00c04fc964ff"], which neither GuidSet nor the wrapper reads back; now it throws JsonException naming 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/Int16Set pairs), WrapperSet_DecimalBacked_ReadsEachTokenAsItsPrimitiveDoes (11 tokens × 2), WrapperSet_GuidBacked_ReadsEachTokenAsItsPrimitiveDoes (9 tokens), WrapperSet_IntegerBacked_ReadsNumbersWrittenAsStrings_OnlyWhenTheOptionsAllowIt, WrapperSet_NumericBacked_RoundTripsUnderWriteAsString_ExactlyAsItsPrimitiveDoes.
  • Oracles: SetWrapperParityTests holds its four numeric rows; WrapperGrammarContractTests JSON leg; JsonOptionsProbeTests under AllowReadingFromString unchanged and green.
  • Fix reverted (ValueSetElementJsonConverter.cs and GuidSet.cs from the parent commit, tests kept): 17 rows of SetJsonConverterTests fail (decimal, Guid and integer tokens), and WrapperGrammarContractTests reports DecimalSet<LenientAmount> JSON string under default options of {"1.5"}: {1.5}, but DecimalSet reads refused and its siblings. Restored afterwards.
  • Full runs: core 981, conventions 324, EF translation 245, AspNetCore 84, NodaTime 196, EF NodaTime 81, integration (LiteralCorpusProbeTests, WrapperArityIntegrationTests, JsonColumnTests) 63 — green. Clone sweep: 65 waived, 0 unwaived, 0 stale.

🤖 Generated with Claude Code

…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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working breaking Changes an answer or a signature — needs a major found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/value-sets Value set families and wrapper arities area/json System.Text.Json and TypeConverter wire forms package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 18, 2026
…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
CaffeinatedCoder merged commit 445790d into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/wrapper-json-element-tokens branch October 18, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/json System.Text.Json and TypeConverter wire forms area/value-sets Value set families and wrapper arities breaking Changes an answer or a signature — needs a major bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrapper set arities read JSON element tokens their primitive set refuses (quoted, padded, signed numbers; braced and unhyphenated Guids)

1 participant