StrongTypedId.NewtonSoft 2.2.0

dotnet add package StrongTypedId.NewtonSoft --version 2.2.0                
NuGet\Install-Package StrongTypedId.NewtonSoft -Version 2.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StrongTypedId.NewtonSoft" Version="2.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StrongTypedId.NewtonSoft --version 2.2.0                
#r "nuget: StrongTypedId.NewtonSoft, 2.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StrongTypedId.NewtonSoft as a Cake Addin
#addin nuget:?package=StrongTypedId.NewtonSoft&version=2.2.0

// Install StrongTypedId.NewtonSoft as a Cake Tool
#tool nuget:?package=StrongTypedId.NewtonSoft&version=2.2.0                

StrongTypedId.NewtonSoft

This package provides support for using StrongTypedId with the NewtonSoft JSON serializer.

Usage

First add the StrongTypedNewtonSoftJsonConverter to your serializer settings.

var settings = new JsonSerializerSettings
{
    Converters = { new StrongTypedNewtonSoftJsonConverter() }
};

var json = JsonConvert.SerializeObject(UserId.New(), settings);

OR

var serializer = new JsonSerializer()
{
    Converters = { new StrongTypedNewtonSoftJsonConverter() }
};

var json = serializer.Serialize(writer, UserId.New());

This will serialize any StrongTypedId, StrongTypedGuid or StrongTypedValue with explicit type information, allowing deserialization even if your model is abstract.

If you furthermore have types you'd prefer serialized as their underlying value, you can add a Newtonsoft.Json.JsonConverter attribute to the type:

[TypeConverter(typeof(StrongTypedIdTypeConverter<UserId, Guid>))]
[StrongTypedIdJsonConverter<UserId, Guid>]

[Newtonsoft.Json.JsonConverter(typeof(NewtonSoftJsonConverter<UserId, Guid>))] // This is the converter for NewtonSoft.

public class UserId: StrongTypedId<UserId, Guid>
{
	public UserId(Guid value) : base(value)
	{
	}
}

Notice how you can have both JsonConverters applied simultaneously to support both WebAPI and NewtonSoft at the same time.

Documentation

Auto generated documentation via DocFx is available here: https://steffenskov.github.io/StrongTypedId/

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.2.0 150 3/12/2025
2.1.0 133 3/12/2025
2.0.0 4,713 12/30/2024
1.9.2 9,529 11/15/2024
1.9.1 97 11/13/2024
1.9.0 107 11/11/2024
1.8.0 14,123 8/26/2024
1.7.0 15,755 5/10/2024
1.6.6 8,194 2/9/2024
1.6.5 323 2/5/2024
1.6.4 175 1/31/2024
1.6.3 700 1/8/2024
1.6.2 5,662 10/10/2023
1.6.1 411 9/8/2023
1.6.0 188 7/18/2023
1.5.1 213 7/15/2023
1.5.0 225 7/15/2023
1.4.3 191 7/11/2023
1.4.2 190 7/11/2023
1.4.1 190 7/11/2023
1.4.0 181 7/10/2023
1.3.0 207 5/21/2023
1.2.0 369 1/21/2023
1.1.5 1,724 8/5/2022
1.1.4 1,341 7/10/2022
1.1.3 452 7/10/2022
1.1.2 452 5/12/2022
1.1.1 439 3/12/2022