[Breaking change]: System.Text.Json default serialization format for TimeSpan #27317
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 6
Issues and PRs for the .NET 6 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Pri1
High priority, do before Pri2 and Pri3
Description
System.Text.Json shipped support for
TimeSpan
in .NET 6 via dotnet/runtime#54186, however this change left out support for source generators. We submitted a fix via dotnet/runtime#62130 and are planning on servicing .NET 6 via dotnet/runtime#62191. This is technically a breaking change since it changes the default serialization format forTimeSpan
in source generators.Version
.NET 6 servicing (exact version TBD)
Previous behavior
In .NET 6 GA, source generators will by default serialize
TimeSpan
values asNew behavior
The serialization format becomes consistent with that used by the reflection-based serializer:
"00:00:01"
Type of breaking change
Reason for change
System.Text.Json source generation is a new feature, our goal is to have serialization behavior that is as consistent as possible with the existing reflection-based serializer. This is to simplify our users' migration to source generators.
Recommended action
We believe that it is unlikely for users to depend on the current
TimeSpan
serialization format, as it redundantly outputs all public properties of the type --the default serialization behavior for objects-- and it is non roundtrip-able.If users do depend on the existing behavior, the recommended course of action is to author a custom converter that outputs the needed properties from TimeSpan:
Feature area
Core .NET libraries
Affected APIs
No response
The text was updated successfully, but these errors were encountered: