Skip to content

Simplify the JsonTempDataSerializer#65483

Draft
dariatiurina wants to merge 2 commits intodotnet:mainfrom
dariatiurina:65231-tempdata-serialization
Draft

Simplify the JsonTempDataSerializer#65483
dariatiurina wants to merge 2 commits intodotnet:mainfrom
dariatiurina:65231-tempdata-serialization

Conversation

@dariatiurina
Copy link
Contributor

@dariatiurina dariatiurina commented Feb 20, 2026

Simplify the JsonTempDataSerializer

Summary

Simplifies the JsonTempDataSerializer by storing type information alongside each value, eliminating the need for heuristic type inference during deserialization. This removes the source-generated JsonTempDataSerializerContext and replaces hand-written per-type deserialization logic with a direct
JsonSerializer.Deserialize call using the stored type.

Changes

  • Changes the internal TempData dictionary type from IDictionary<string, object?> to IDictionary<string, (object? Value, Type? Type)> so values carry their original type through the pipeline.
  • Replaces the serialization format: each value is now stored as { "type": "<type-fullname>", "value": <json> } instead of a raw JSON value.
  • Removes JsonTempDataSerializerContext (source-generated context with ~30 [JsonSerializable] attributes) — no longer needed since the type is stored explicitly.
  • Removes heuristic deserialization methods (DeserializeElement, DeserializeString, DeserializeArray, DeserializeObject, GetArrayTypeInfo, GetStringType) that inferred types from JsonValueKind.
  • Simplifies CanSerialize to use a static HashSet<Type> of supported types.
  • Normalizes ICollection<T> types (e.g., List<T>, HashSet<T>) to T[] during serialization.
  • Updates ITempDataProvider, ITempDataSerializer, TempDataService, CookieTempDataProvider, SessionStorageTempDataProvider, and TempData to use the new tuple-based dictionary.

Testing

  • Replaces individual per-type deserialization tests with a single parameterized RoundTrip theory covering int, bool, string, Guid, DateTime, arrays, and dictionaries.
  • Adds dedicated tests for null values, enums, enum arrays, List<T> → array normalization, and HashSet<T> → array normalization.
  • Expands ValidTypes coverage with additional types (string[], bool[], DateTime[], Dictionary<string,T> variants, enums, List, HashSet).

Fixes #65231

@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Feb 20, 2026
@dariatiurina dariatiurina self-assigned this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Blazor] Reconsider temp data serialization strategy.

1 participant