OpFlow.Converters.NewtonsoftJson 1.0.1

dotnet add package OpFlow.Converters.NewtonsoftJson --version 1.0.1
                    
NuGet\Install-Package OpFlow.Converters.NewtonsoftJson -Version 1.0.1
                    
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="OpFlow.Converters.NewtonsoftJson" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpFlow.Converters.NewtonsoftJson" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="OpFlow.Converters.NewtonsoftJson" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpFlow.Converters.NewtonsoftJson --version 1.0.1
                    
#r "nuget: OpFlow.Converters.NewtonsoftJson, 1.0.1"
                    
#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.
#:package OpFlow.Converters.NewtonsoftJson@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpFlow.Converters.NewtonsoftJson&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=OpFlow.Converters.NewtonsoftJson&version=1.0.1
                    
Install as a Cake Tool

OpFlow.Converters.NewtonsoftJson

Newtonsoft.Json converters for OpFlow discriminated unions.

This package provides high‑quality, contract‑based JSON converters for the OpFlow union types:

  • Operation<T>
  • Error

It ensures stable, predictable JSON serialization and deserialization for all OpFlow union cases, without relying on reflection for contract discovery. The converters enforce OpFlow’s invariants and guarantee round‑trip safety.


✨ Features

  • Full support for Operation<T>:

    • Success
    • Failure
  • Full support for all Error union cases:

    • Validation
    • NotFound
    • Unauthorized
    • Unexpected
  • Contract‑based JSON schema (no hidden fields, no magic)

  • Non‑generic OpFlowOperationConverter works for any Operation<T>

  • Structured exception serialization for Unexpected errors

  • Case‑insensitive JSON parsing

  • Clear error messages for malformed payloads

  • Zero reflection for property access

  • Minimal reflection only for generic type construction (safe and unavoidable)


📦 Installation

Install via NuGet:

dotnet add package OpFlow.Converters.NewtonsoftJson

Or via the NuGet Package Manager:

Install-Package OpFlow.Converters.NewtonsoftJson

🚀 Getting Started

Register the converters

You can register the converters manually:

var settings = new JsonSerializerSettings
{
    Converters =
    {
        new OpFlowErrorConverter(),
        new OpFlowOperationConverter()
    }
};

Or use the convenience extension method:

var settings = new JsonSerializerSettings()
    .AddOpFlowConverters();

🔄 Usage Examples

Serialize a successful operation

var op = new Operation<string>.Success("Hello world");

string json = JsonConvert.SerializeObject(op, settings);

Produces:

{
  "operation": {
    "kind": "success",
    "result": "Hello world"
  }
}

Serialize a failed operation

var op = new Operation<string>.Failure(
    new Error.NotFound("User not found")
);

string json = JsonConvert.SerializeObject(op, settings);

Produces:

{
  "operation": {
    "kind": "failure",
    "error": {
      "errorType": "notfound",
      "message": "User not found"
    }
  }
}

Deserialize

Operation<string> result =
    JsonConvert.DeserializeObject<Operation<string>>(json, settings);

Pattern‑match the result:

switch (result)
{
    case Operation<string>.Success s:
        Console.WriteLine($"Success: {s.Result}");
        break;

    case Operation<string>.Failure f:
        Console.WriteLine($"Error: {f.Error}");
        break;
}

📐 JSON Contract

Operation<T>

{
  "operation": {
    "kind": "success" | "failure",
    "result": <T>,          // success only
    "error": <ErrorObject>  // failure only
  }
}

Error

Each error case includes a discriminator:

{
  "error": {
    "errorType": "validation" | "notfound" | "unauthorized" | "unexpected",
    "message": "string",
    "fields": [ "string" ],     // validation only
    "exception": { ... }        // unexpected only
  }
}

🧪 Testing

This package is fully covered by a dedicated test suite:

  • Round‑trip serialization for all union cases
  • Error handling for malformed JSON
  • Case‑insensitive parsing
  • Nested error serialization
  • Multiple generic types (Operation<string>, Operation<int>, etc.)

📄 License

MIT License — see the LICENSE file for details.


🤝 Contributing

Contributions are welcome.
If you’d like to improve the converters, add new union support, or enhance the JSON contract, feel free to open an issue or submit a pull request.


  • OpFlow — the core discriminated union types (Error, Operation<T>)
  • OpFlow.Converters.SystemTextJson (coming soon) — STJ converters for OpFlow unions

❤️ About OpFlow

OpFlow is a narrative‑driven pipeline and operation framework designed for clarity, expressiveness, and developer experience.
These converters ensure that OpFlow’s union types serialize cleanly and predictably across service boundaries.

Product Compatible and additional computed target framework versions.
.NET 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. 
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
1.0.1 136 2/13/2026
1.0.0 127 2/11/2026