Skip to content

HybridCache: richer detection for field-only types (ref STJ) - #6118

Merged
mgravell merged 3 commits into
dotnet:mainfrom
mgravell:marc/hc_json_deep
Mar 18, 2025
Merged

HybridCache: richer detection for field-only types (ref STJ)#6118
mgravell merged 3 commits into
dotnet:mainfrom
mgravell:marc/hc_json_deep

Conversation

@mgravell

@mgravellmgravell commented Mar 14, 2025

Copy link
Copy Markdown
Contributor

HybridCache uses System.Text.Json for the default serializer, which has some opinions on fields; this means that named-tuples (or value-tuples generally), and types that use value tuples or otherwise field-only values, can lose data.

We already detect value-tuples specifically as the root type, but real-world usage has highlit wider ranges of scenarios. This PR adds deeper detection for this scenario, applying the same workaround. It duly considers collection types and recursion scenarios.

fixdotnet/aspnetcore#60934

Microsoft Reviewers: Open in CodeFlow

@mgravell

mgravell commented Mar 14, 2025

Copy link
Copy Markdown
ContributorAuthor

Thought: we should explicitly restrict our override behaviour to scenarios that use the inbuilt STJ default options instance, not just ones that don't handle fields. If someone uses their own STJ options: we should respect it. The mechanism for people to do this is new and non-disclosed, so there is no issue changing that behaviour, i.e. right now the number of times anyone will have ever supplied a non-default STJ options is zero or a rounding error asymptotically approaching zero.

@mgravell
mgravell merged commit 354bf8d into dotnet:mainMar 18, 2025
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Apr 18, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hybrid Cache silently fails to correctly handle cached tuples

2 participants

@mgravell@DeagleGross