Repository navigation
Description
ISerializationProvider is built on TextWriter and TextReader:
public bool TrySerialize(object obj, TextWriter writer);
public T? Deserialize<T>(TextReader reader)
public Task<bool> TrySerializeAsync(object obj, TextWriter writer, CancellationToken cancellationToken = default)
public Task<T?> DeserializeAsync<T>(TextReader reader, CancellationToken cancellationToken = default)That choice is what stops the serialization providers from ever becoming genuinely async, so it blocks the serialization half of #8 specifically rather than being a general style preference.
Why the parameter type is the blocker
System.Text.Json's asynchronous entry points are JsonSerializer.SerializeAsync(Stream, …) and JsonSerializer.DeserializeAsync<T>(Stream, …). There is no TextWriter or TextReader overload of either, and there is no adapter that recovers one, because the async path exists precisely so the serializer can write UTF-8 bytes straight to a stream without materialising a string.
So a provider handed a TextWriter has two options, and both are the thing #8 is about:
- serialize synchronously into the writer and wrap it in
Task.Run, which is what happens today viaProviderHelpers.RunAsync() - serialize to an intermediate buffer, then write that to the writer
JsonSerializationProvider currently declares only TrySerialize(object, TextWriter) and inherits every other member, so all four of its async paths are Task.Run wrappers over synchronous work.
The same reasoning applies to the other three providers to varying degrees. Newtonsoft.Json is TextWriter-native and genuinely has no async story worth reaching for, so it is the one case where the current signature costs nothing.
Why it isn't just "add a Stream overload"
ISerializationProvider uses default interface implementations, so adding Stream overloads alongside the existing ones is source-compatible. The problem is that it leaves two parallel families where the TextWriter one is a trap: it looks equally good at the call site and silently gives you the Task.Run path. The compression conversion in #14 worked because there was one obvious primitive per direction and overriding it converted every derived path. Here that would only be true if Stream became the primitive and the TextWriter members were re-expressed over it.
Encoding matters too. TextWriter carries its own encoding, whereas SerializeAsync writes UTF-8 unconditionally. Layering the existing members over a Stream primitive has to preserve what today's callers get, which is not automatically UTF-8.
Suggested scope
Design work, not a mechanical change, and it probably wants to land with the ValueTask conversion in release 2 of #8 since both change the same signatures and both are breaking. Recording it now so the constraint is written down rather than rediscovered.
Activity
matt-edmondson commentedon Sep 8, 2026
Triage
Priority: Medium Effort: Medium
What needs to be done:
ISerializationProvider'sTextWriter/TextReader-based signatures block genuine async serialization, sinceSystem.Text.Json's async entry points only exist overStream. Needs a design decision on re-expressing the interface over aStreamprimitive (withTextWritermembers layered on top, preserving encoding behaviour) rather than adding a parallelStreamoverload that silently traps callers on the slow path.Suggested next steps / acceptance criteria:
Streamthe base member, re-expressTextWriter/TextReaderoverloads over itTextWriter's caller-chosen encoding rather than hard-coding UTF-8 from theStreampathNewtonsoftJsonSerializationProvideris unaffected (genuinelyTextWriter-native, no async story to gain)ValueTaskconversion work in Essentials#8, since both are breaking and touch the same signaturesBlockers / dependencies: Depends on / should ship with Essentials#8 (same breaking release, same signature surface). No other blockers identified.
Generated by Claude Code
matt-edmondson commentedon Sep 28, 2026
Decision (maintainer, 2026-09-28)
ISerializationProvideroverStream.Streambecomes the primitive, and theTextWriter/TextReadermembers are layered over it, preserving the encoding the caller chose. A parallelStreamoverload family is not acceptable.ValueTask<T>.Next reader: design and implement the
Streamprimitive so thatJsonSerializationProviderusesJsonSerializer.SerializeAsync/DeserializeAsync, while Newtonsoft keeps itsTextWriter-native path. Land it together with #8 in one major release.Generated by Claude Code
matt-edmondson commentedon Nov 3, 2026
Triage
ISerializationProviderStream. It needs a major version bump.Re-triaged because the thread changed after the original triage.
Generated by Claude Code