Repository navigation
Description
Found by a pre-release sweep of main @ 577b85e (lens: framework-heuristics); reproduced in a scratch test.
Problem
A property declared as IRangeSetOperations<TSet> or IRangeSetFactory<TSet, TRange, T> is written as {} by System.Text.Json, with no error. The value is lost on write, and reading {} back throws NotSupportedException.
AGENTS.md: "The range and set interfaces carry InterfaceDeclaredJsonConverter (write through the runtime type, refuse a read) … so a value's wire form never depends on how it was declared." IRangeSet<,>, IRangeSetProducer<,,>, IRange<T> and IValueSet<T> carry it. These do not:
IRangeSetOperations<TSet>(src/CodoMetis.ValueRanges/Core/IRangeSetOperations.cs:15), new in 11.0.0IRangeSetFactory<TSet, TRange, T>(Core/IRangeSetFactory.cs:18), new in 11.0.0IRangeFactory<TRange, T>(Core/IRangeFactory.cs:29), also on 10.xIValueSetFactory<TSet, T>(Core/IValueSetFactory.cs:19), also on 10.x
The convention test leaves them out on purpose. JsonDefaultContractTests.DeclarableInterfacesOf (test/CodoMetis.ValueRanges.Conventions.Tests/JsonDefaultContractTests.cs:208) skips every interface with a static abstract member, "whose static abstract members rule them out as a declared type". They rule it out as a type argument only (CS8920). A property, a field or a record parameter of such a type compiles.
Scenario
public sealed record A(IRangeSetOperations<DateRangeSet> V);
public sealed record B(IRangeSetFactory<DateRangeSet, DateRange, DateOnly> V);
public sealed record C(IRangeFactory<DateRange, DateOnly> V);
public sealed record D(IValueSetFactory<StringSet, string> V);Measured on 577b85e, JsonSerializer.Serialize with nothing registered:
IRangeSetOperations: {"V":{}}
IRangeSetFactory: {"V":{}}
IRangeFactory: {"V":{}}
IValueSetFactory: {"V":{}}
IRangeSetProducer: {"V":"[2026-03-01,2026-03-05]"}
IRangeSet: {"V":"{[2026-03-01,2026-03-05]}"}
It needs a declaration typed as one of these interfaces outside generic code. A DTO generic over TSet closes to the set type and is written correctly.
Change
Put [JsonConverter(typeof(InterfaceDeclaredJsonConverter))] on the four interfaces, and drop the static-abstract exclusion from DeclarableInterfacesOf, so a new interface without the attribute fails there. Check the Native AOT consumer in the smoke test afterwards, since the attribute lands on interfaces with static abstract members.
IRangeFactory<,> and IValueSetFactory<,> have the same gap on release/10.x. That half is a silent fix on a released line, so it ships there as a minor with a ### Changed answers row: a port issue under #521.
Test
JsonDefaultContractTests with the exclusion removed: every interface in the core namespace that a range, a range set or a value set implements writes the literal when a property is declared as it. It fails with the attributes removed.
Activity
Merge pull request #587 from CaffeinatedCoder/fix/579-json-for-factor…