StrongOf.Json
3.1.2
Requires NuGet 2.12 or higher.
dotnet add package StrongOf.Json --version 3.1.2
NuGet\Install-Package StrongOf.Json -Version 3.1.2
<PackageReference Include="StrongOf.Json" Version="3.1.2" />
<PackageVersion Include="StrongOf.Json" Version="3.1.2" />
<PackageReference Include="StrongOf.Json" />
paket add StrongOf.Json --version 3.1.2
#r "nuget: StrongOf.Json, 3.1.2"
#:package StrongOf.Json@3.1.2
#addin nuget:?package=StrongOf.Json&version=3.1.2
#tool nuget:?package=StrongOf.Json&version=3.1.2
StrongOf.Json
System.Text.Json converters for StrongOf types. The converters support NativeAOT and trimming. Applications must supply generated JSON metadata as shown below.
NativeAOT and source generation
Install StrongOf.Json and use a JsonSerializerContext for every serialized DTO. Put the converter attribute
on the strong type itself when StrongOf generates that type in the same project:
using System.Text.Json;
using System.Text.Json.Serialization;
using StrongOf.Json;
using StrongOf.SourceGeneration;
UserDto user = new() { Id = UserId.From(Guid.NewGuid()) };
string json = JsonSerializer.Serialize(user, AppJsonContext.Default.UserDto);
UserDto restored = JsonSerializer.Deserialize(json, AppJsonContext.Default.UserDto)!;
[StrongGuid]
[JsonConverter(typeof(StrongGuidJsonConverter<UserId>))]
public sealed partial class UserId;
public sealed class UserDto
{
public UserId Id { get; set; } = null!;
}
[JsonSerializable(typeof(UserDto))]
internal partial class AppJsonContext : JsonSerializerContext;
Set these properties in the application project:
<PropertyGroup>
<PublishAot>true</PublishAot>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>
The StrongOf and System.Text.Json generators cannot inspect each other's generated implementation in the same
compilation. A converter only on a DTO property is therefore insufficient for a newly generated strong type:
the JSON generator can otherwise emit a call to a nonexistent parameterless constructor (CS7036). The
explicit converter attribute on the strong type avoids this. Property-level converters remain useful for
hand-written types or types already compiled in another assembly, such as StrongOf.Domains.
Options-based registration
Options still need a generated metadata resolver. For a type-level converter as above:
JsonSerializerOptions options = new()
{
WriteIndented = true,
TypeInfoResolver = AppJsonContext.Default,
};
AppJsonContext context = new(options);
string json = JsonSerializer.Serialize(user, context.UserDto);
For hand-written or precompiled strong types, converters may also be added to options.Converters.
Registering converters alone does not supply metadata for containing DTOs. Avoid reflection-based serializer
overloads in NativeAOT applications; pass the generated JsonTypeInfo<T> or JsonSerializerContext instead.
Available converters and wire format
| Converter | JSON representation |
|---|---|
StrongBooleanJsonConverter<T> |
Boolean; also accepts strings when reading |
StrongGuidJsonConverter<T> |
GUID string |
StrongStringJsonConverter<T> |
String |
StrongInt32JsonConverter<T> |
Numeric string |
StrongInt64JsonConverter<T> |
Numeric string |
StrongDecimalJsonConverter<T> |
Numeric string |
StrongDoubleJsonConverter<T> |
Numeric string |
StrongCharJsonConverter<T> |
Single-character string |
StrongDateTimeJsonConverter<T> |
ISO date-time string |
StrongDateTimeOffsetJsonConverter<T> |
ISO date-time string, preserving the offset |
StrongTimeSpanJsonConverter<T> |
TimeSpan string in c format |
DateTimeOffset input accepts seconds with zero to seven fractional digits and either Z or an explicit
offset (+02:00, -05:30). Output uses the round-trip o format. An input without an offset is rejected.
The existing converters return null for unparseable string values; callers must validate required fields.
Executable example
The NativeAOT sample publishes and runs round trips for all eleven converters with JSON reflection disabled.
Installation
dotnet add package StrongOf.Json
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.1.2 | 240 | 10/4/2026 |
| 3.0.35 | 111 | 9/23/2026 |
| 3.0.31 | 2,446 | 6/17/2026 |
| 3.0.29 | 455 | 5/19/2026 |
| 2.1.37 | 818 | 4/21/2026 |
| 2.1.31 | 423 | 3/30/2026 |
| 2.1.26 | 818 | 3/7/2026 |
| 2.1.8 | 145 | 2/28/2026 |
| 1.2.15 | 3,359 | 4/26/2025 |
| 1.2.8 | 431 | 4/9/2025 |
| 1.2.7 | 2,532 | 2/18/2025 |
| 1.2.7-ga639164e54 | 219 | 2/18/2025 |
| 1.2.4 | 1,843 | 11/28/2024 |
| 1.2.4-g0988d2c02d | 212 | 11/28/2024 |
| 1.2.2 | 606 | 11/15/2024 |
| 1.2.2-gbc3f3048e7 | 193 | 11/15/2024 |
| 1.1.4 | 590 | 11/12/2024 |
| 1.1.4-g6e854f6d6d | 188 | 11/12/2024 |
| 1.1.2 | 273 | 11/5/2024 |
| 1.1.2-g0a1a51912f | 182 | 11/5/2024 |