JsonPatchBind 0.0.1

dotnet add package JsonPatchBind --version 0.0.1
                    
NuGet\Install-Package JsonPatchBind -Version 0.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="JsonPatchBind" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonPatchBind" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="JsonPatchBind" />
                    
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 JsonPatchBind --version 0.0.1
                    
#r "nuget: JsonPatchBind, 0.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 JsonPatchBind@0.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=JsonPatchBind&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=JsonPatchBind&version=0.0.1
                    
Install as a Cake Tool

= JsonPatchBind

A lightweight library for handling partial updates in ASP.NET Core APIs without JSON Patch.

Description

When building APIs for partial updates (PATCH requests), developers often face challenges such as:

• Differentiating between an explicit null and an omitted field. • Avoiding overwriting fields that were not sent by the client. • Ensuring accurate schema documentation with Swagger/Swashbuckle.

JsonPatchBind elegantly addresses these challenges by introducing the Optional<T> type.

Key Benefits:

Field Presence Tracking: Determine if a property was included in the JSON payload (even if its value is null). • Safe Updates: Update only the fields provided in the request, leaving others unchanged. • Native JSON Integration: Seamless serialization/deserialization via System.Text.Json. • Swagger Support: Automatic schema generation for Optional<T> fields.

Features

Optional<T> Wrapper: - HasValue = true → Field was sent (value can be null). - HasValue = false → Field was omitted.

Custom JSON Converter: Serializes/deserializes Optional<T> correctly while handling nulls.

Swagger Schema Filter: Displays Optional<T> as nullable fields in OpenAPI documentation.

ASP.NET Core Integration: Works seamlessly with [FromBody] model binding.

No External Dependencies: Built using standard .NET components.

Why Not JSON Patch?

Although JSON Patch (RFC 6902) is a standard, it comes with several drawbacks:

❌ Clients must send complex operations (replace, remove, add).

❌ It overcomplicates simple partial updates.

❌ It demands extra validation.

= Сomparison Table: When to Use

Criteria JsonPatchBind JSON Patch
Use Case Simple partial updates using Optional<T> Updates using operations (replace, remove, add)
Client Complexity Simple JSON payload structure Requires constructing complex operation objects
Field Tracking Clearly differentiates between explicit null and omitted fields Does not explicitly track field presence
Swagger Integration Automatically generates accurate schema Often requires manual adjustments
Validation Minimal additional validation needed Requires extra validation steps

= Pros and Cons: JSON Patch vs. JsonPatchBind

Aspect JsonPatchBind JSON Patch
Simplicity ✅ Simple and intuitive approach ❌ More complex payload structure
Field Tracking ✅ Explicitly determines if a field was sent (even if null) ❌ Lacks built-in mechanism for field tracking
Swagger Support ✅ Built-in support for accurate schema generation ❌ Requires additional configuration
Validation ✅ Minimal extra validation ❌ Additional data validation is often necessary
Standardization ❌ Custom solution (not an official standard) ✅ Official standard (RFC 6902)

= When to Use JsonPatchBind?

Use JsonPatchBind if:

• You need to implement partial updates without overcomplicating your logic.

• You require precise tracking of which fields were sent by the client.

• You want to minimize extra validation and work seamlessly with OpenAPI/Swagger.

• You do not need the full set of JSON Patch operations.

= Installation & Integration

  1. Installation: Add the package to your project via NuGet:

    dotnet add package JsonPatchBind
    
  2. Usage in a Controller: Example model:

    public class UpdateUserModel
    {
        public Optional<string> FirstName { get; set; }
        public Optional<string> LastName { get; set; }
        public Optional<string> Email { get; set; }
    }
    
Product Compatible and additional computed target framework versions.
.NET 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.  net10.0 was computed.  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
0.0.1 474 2/1/2025