Fluent.Unions.NewtonsoftJson
1.1.0
dotnet add package Fluent.Unions.NewtonsoftJson --version 1.1.0
NuGet\Install-Package Fluent.Unions.NewtonsoftJson -Version 1.1.0
<PackageReference Include="Fluent.Unions.NewtonsoftJson" Version="1.1.0" />
<PackageVersion Include="Fluent.Unions.NewtonsoftJson" Version="1.1.0" />
<PackageReference Include="Fluent.Unions.NewtonsoftJson" />
paket add Fluent.Unions.NewtonsoftJson --version 1.1.0
#r "nuget: Fluent.Unions.NewtonsoftJson, 1.1.0"
#:package Fluent.Unions.NewtonsoftJson@1.1.0
#addin nuget:?package=Fluent.Unions.NewtonsoftJson&version=1.1.0
#tool nuget:?package=Fluent.Unions.NewtonsoftJson&version=1.1.0
![]()
Fluent.Unions.NewtonsoftJson
Newtonsoft.Json support for Fluent.Unions, for projects that do not use System.Text.Json. It does what the core does for System.Text.Json: Option<T> is written as its value or null, your own unions keep their case name, and results refuse to serialize. It depends on Newtonsoft.Json (MIT license).
Warning: without
AddFluentUnions(), Newtonsoft.Json writes aResultas a plain object with the full exception, including its class name, message andStackTraceString. This also happens in ASP.NET Core withAddNewtonsoftJson(). RegisterAddFluentUnions()on everyJsonSerializerSettingsand convert results before returning them.
Installation
dotnet add package Fluent.Unions.NewtonsoftJson
Usage
using Fluent.Unions;
using Fluent.Unions.NewtonsoftJson;
using Newtonsoft.Json;
var settings = new JsonSerializerSettings().AddFluentUnions();
public record CustomerDto(string Name, Option<string> Nickname);
JsonConvert.SerializeObject(new CustomerDto("Ada", Option.None), settings); // {"Name":"Ada","Nickname":null}
JsonConvert.SerializeObject(new CustomerDto("Ada", "Countess"), settings); // {"Name":"Ada","Nickname":"Countess"}
Your own unions are written with $type and $value. Apply the converter with an attribute:
[JsonConverter(typeof(UnionJsonConverter))]
public union Shape(Circle, Square);
Every result type throws NotSupportedException when written or read: Result, Result<T> and your own types declared with [FluentResult<TError>]. Convert them first. See the documentation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fluent.Unions (>= 1.1.0)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.