Skip to content

fix: a value declared as its factory interface is written as its literal in JSON (#581) - #598

Merged
CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/581-json-factory-interfaces-10.x
Nov 30, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/581-json-factory-interfaces-10.x

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #581

The port of #579 (PR #587, commit 689a609 on main), cherry-picked with -x and adapted to this line. Merge after #597: this branch is built on it, because #597 removes the ### Changed answers section the revert of #487 leaves behind and this PR adds one back holding only this row. Until #597 merges, the diff here shows its commit too.

Problem

On 10.x a property declared as IRangeFactory<TRange, T> or IValueSetFactory<TSet, T> was written as {} by System.Text.Json, with no error, and nothing could read {} back. Neither interface carried InterfaceDeclaredJsonConverter, which IRange<T>, the shape interfaces and IValueSet<T> do, and JsonDefaultContractTests skipped interfaces with static abstract members as "not declarable". They are not declarable as a type argument (CS8920); a property of such a type compiles.

Change

As on main: both interfaces carry [JsonConverter(typeof(InterfaceDeclaredJsonConverter))], the converter accepts them and names the right concrete type when it refuses a read, and JsonDefaultContractTests checks every interface of the core namespace a range or value set implements.

Differences from main, where the cherry-pick conflicted or did not apply:

  • No range set interfaces. 10.x has no IRangeSet, IRangeSetOperations, IRangeSetFactory or IRangeSetProducer: their two attribute hunks, the converter's range set message arm, the convention test's range set check and the docs' mention of them are left out. A range variant has three of the package's interfaces (IRange<T>, its shape, IRangeFactory), not four.
  • Seed. operations-interface-without-json-converter patches a file this line lacks; this line has factory-interface-without-json-converter, stripping the attribute from IRangeFactory.
  • Changelog. The row is under ### Changed answers in [10.5.0] (root and core), linking 10.x: a range or value set declared as its factory interface is written as {} in JSON (port of #579) #581 and the migration section, with the line 10.4.0 opens with. main has it under ### Breaking of 11.0.0.
  • docs/migration.md. A new ## Changed answers in 10.5.0 at the end, holding "Check JSON for a property declared as a factory interface", comparing 10.4.0 with 10.5.0 and without the bullet on the range set interfaces. Claim M23 points at it, worded for the factory interfaces only. The 10.5.0 carry PR owes main this section header.
  • docs/serialization.md. "Before 10.5" where main says "Before 11.0".

Tests

  • JsonDefaultContractTests fails with the attribute removed from IRangeFactory (the seed: "DateRange.EmptyRange empty: declared as IRangeFactory2, the wire form differs") and, separately, from IValueSetFactory ("DateSet {}: declared as IValueSetFactory2, …"); passes with both.
  • Locally: conventions 422 and core 1403 pass.

🤖 Generated with Claude Code

CaffeinatedCoder and others added 2 commits November 30, 2026 14:05
This reverts commit ae9473c, merge of PR #571, the port of #487 to
release/10.x (reverting the mainline, -m 1).

With the port, a final Select of ToRangeSet() ran in the database where
it ran in memory on 10.4.0: a set holding int.MaxValue failed with 22003,
and at the ends of a date type the result counted one range more. 10.5.0
is a stable minor and takes no changed answer, so the translation, the
guard's bridge, its tests, seeds, claims, changelog lines, docs and the
migration section go. The feature ships in 11.0.0 only.

The one conflict was the bridge's alias line, which #573 made invariant;
it goes with the bridge. The NodaTime EF changelog loses the "No change
in this package." line the revert would have restored above #573's
Fixed entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ral in JSON (#581)

A property declared as IRangeFactory<TRange, T> or IValueSetFactory<TSet,
T> was written as {} by System.Text.Json, with no error: the value was
lost on write. The other interfaces of the package carry
InterfaceDeclaredJsonConverter, which writes through the runtime type and
refuses a read. These two did not, and JsonDefaultContractTests left them
out on purpose, as interfaces whose static abstract members rule them out
as a declared type. They rule them out as a type argument only (CS8920);
a property, a field or a record parameter of such a type compiles.

Both interfaces carry the attribute, and the converter handles them and
names the right concrete type when it refuses a read. The convention test
checks every interface of the core namespace that a range or a value set
implements, handing the declared type over as a Type, which is how a
property reaches the serializer.

Port of #579 to release/10.x. Differences from main: 10.x has no
IRangeSet, IRangeSetOperations, IRangeSetFactory or IRangeSetProducer, so
the two attributes on the operations and range set factory interfaces,
the converter's range set arm and the range set check of the convention
test are left out, and a range variant has three of the package's
interfaces, not four. The seed is factory-interface-without-json-converter
(IRangeFactory), as operations-interface-without-json-converter patches a
file this line does not have. The row is under ### Changed answers in
[10.5.0], linking #581, with a new "Changed answers in 10.5.0" section in
docs/migration.md comparing 10.4.0 and 10.5.0; claim M23 points at it.

With either attribute removed, JsonDefaultContractTests fails naming the
interface.

Found-By: CA
Defect-Class: JSON
(cherry picked from commit 689a609)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.5.0 milestone Nov 30, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred area/json System.Text.Json and TypeConverter wire forms package/core Affects CodoMetis.ValueRanges severity/medium Inconsistency or failure in a narrow scenario stacked Base is another open PR; merge in order, CI does not run until it targets main labels Nov 30, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 0ff5738 into release/10.x Nov 30, 2026
16 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/581-json-factory-interfaces-10.x branch November 30, 2026 13:15
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 bug Something isn't working package/core Affects CodoMetis.ValueRanges severity/medium Inconsistency or failure in a narrow scenario silent Answers wrongly without throwing — fixes go in the next major, never deferred stacked Base is another open PR; merge in order, CI does not run until it targets main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant