Portable.System.DateTimeOnly.Json
9.1.0-beta1
dotnet add package Portable.System.DateTimeOnly.Json --version 9.1.0-beta1
NuGet\Install-Package Portable.System.DateTimeOnly.Json -Version 9.1.0-beta1
<PackageReference Include="Portable.System.DateTimeOnly.Json" Version="9.1.0-beta1" />
<PackageVersion Include="Portable.System.DateTimeOnly.Json" Version="9.1.0-beta1" />
<PackageReference Include="Portable.System.DateTimeOnly.Json" />
paket add Portable.System.DateTimeOnly.Json --version 9.1.0-beta1
#r "nuget: Portable.System.DateTimeOnly.Json, 9.1.0-beta1"
#addin nuget:?package=Portable.System.DateTimeOnly.Json&version=9.1.0-beta1&prerelease
#tool nuget:?package=Portable.System.DateTimeOnly.Json&version=9.1.0-beta1&prerelease
Portable.System.DateTimeOnly.Json
The System.Text.Json
NuGet package contains the built-in support for the System.DateOnly
and System.TimeOnly
types serialization/deserialization. Of course, the backported versions of the same types from the Portable.System.DateTimeOnly
NuGet package are not supported by default by this library. If you already use the portable versions of these types in your code and want to make them compatible with the System.Text.Json
you can implement custom converters or use this package for cross-framework compatible approach.
Reflection-based Serialization
The package provides two concrete implementations of the System.Text.Json.Serialization.JsonConverter<T>
class: System.Text.Json.DateOnlyConverter
and System.Text.Json.TimeOnlyConverter
for converting System.DateOnly
and System.TimeOnly
data types. You can use this converter as usual System.Text.Json
converters: with the System.Text.Json.Serialization.JsonConverterAttribute
attribute or System.Text.Json.JsonSerializerOptions.Converters
property.
The main disadvantage of this "direct" approach for configuring System.DateOnly
and System.TimeOnly
data types handling by the System.Text.Json
library is that in this case you'll always use the backported converters even if your code runs on .NET 6 and later. The package also provides two helper attributes System.Text.Json.DateOnlyConverterAttribute
and System.Text.Json.TimeOnlyConverterAttribute
for mitigating this problem. These attributes use built-in converters on .NET 6 and later and fall back to the backported one in other cases.
Source Generators Workaround
Unfortunately, attributes-based approach will not work if you'll try to use System.DateOnly
and/or System.TimeOnly
data types with the System.Text.Json
source generators. The only way to make generated code compilable is to use any type names not equal to System.DateOnly
and/or System.TimeOnly
available in object graph processed by the source generator.
The package provides two helper types: System.Text.Json.JsonDateOnly
and System.Text.Json.JsonTimeOnly
to solve this problem. These types have no public properties, but they provide implicit conversion operations from/to the System.DateOnly
and System.TimeOnly
data types respectively. You can use them safely in your JSON-mapping objects with any kind of serialization available in the System.Text.Json
library. These types have custom System.Text.Json.Serialization.JsonConverterAttribute
applied with helper converters that delegate work to System.Text.Json.DateOnlyConverter
and System.Text.Json.TimeOnlyConverter
types without code duplication.
Contributors
Thanks a lot for all contributors. See the full list of project supporters in the CONTRIBUTORS file.
SAST Tools
This project uses PVS-Studio - static analyzer for C, C++, C#, and Java code.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Portable.System.DateTimeOnly (>= 9.0.0)
- System.Text.Json (>= 9.0.2)
-
net8.0
- Portable.System.DateTimeOnly (>= 9.0.0)
- System.Text.Json (>= 9.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Portable.System.DateTimeOnly.Json:
Package | Downloads |
---|---|
Shinya.Core
Shinya.Framework |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.1.0-beta1 | 268 | 2 months ago |
9.0.0 | 1,047 | 4 months ago |
9.0.0-beta1 | 282 | 5 months ago |
8.0.2 | 1,129 | 7 months ago |
8.0.1 | 6,773 | 9 months ago |
8.0.0 | 4,540 | 6/16/2024 |
- The `System.Text.Json.DateOnly` class was renamed to `System.Text.Json.JsonDateOnly` to prevent ambiguous name resolution problems.
- The `System.Text.Json.TimeOnly` class was renamed to `System.Text.Json.JsonTimeOnly` to prevent ambiguous name resolution problems.
- Thanks, @Swimburger, for pointing out this problem with breaking out the existing code just by adding the NuGet package.