Morcatko.AspNetCore.JsonMergePatch 2.0.0-beta05

This is a prerelease version of Morcatko.AspNetCore.JsonMergePatch.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Morcatko.AspNetCore.JsonMergePatch --version 2.0.0-beta05
NuGet\Install-Package Morcatko.AspNetCore.JsonMergePatch -Version 2.0.0-beta05
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="Morcatko.AspNetCore.JsonMergePatch" Version="2.0.0-beta05" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Morcatko.AspNetCore.JsonMergePatch --version 2.0.0-beta05
#r "nuget: Morcatko.AspNetCore.JsonMergePatch, 2.0.0-beta05"
#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 Morcatko.AspNetCore.JsonMergePatch as a Cake Addin
#addin nuget:?package=Morcatko.AspNetCore.JsonMergePatch&version=2.0.0-beta05&prerelease

// Install Morcatko.AspNetCore.JsonMergePatch as a Cake Tool
#tool nuget:?package=Morcatko.AspNetCore.JsonMergePatch&version=2.0.0-beta05&prerelease

JSON Merge Patch support for ASP.NET Core 2.x

JSON Merge Patch

  • RFC 7396
  • performs partial resource update similar to JSON Patch
  • Supports Swagger
  • netstandard 2.0
C# object:
var backendModel = new Model()
{
    Name = "James Bond"
    Age = "45"
    Weapon = "Gun"
}

JSON Merge Patch:
{
    "Weapon": "Knife"
}

resulting C# object:
{
    Name = "James Bond"
    Age = "45"
    Weapon = "Knife"
}

How to

See testApp2.0 for sample

  1. Install Morcatko.AspNetCore.JsonMergePatch nuget
  2. Add to your startup class
using Morcatko.AspNetCore.JsonMergePatch;

public void ConfigureServices(IServiceCollection services)
{
    ...
    services
        .AddMvc()
        .AddJsonMergePatch();
    ...
}
  1. Use in your controller
using Morcatko.AspNetCore.JsonMergePatch;

[HttpPatch]
[Consumes(JsonMergePatchDocument.ContentType)]
public void Patch([FromBody] JsonMergePatchDocument<Model> patch)
{
    ...
    patch.ApplyTo(backendModel);
    ...
}
  1. Swagger config (optional)

copy & paste this class into your app - https://github.com/Morcatko/Morcatko.AspNetCore.JsonMergePatch/blob/master/test/testApp2.0/JsonMergePatchDocumentOperationFilter.cs

services.AddSwaggerGen(c =>
    {
        c.OperationFilter<JsonMergePatchDocumentOperationFilter>();
    });

How to - unit testing

See Morcatko.AspNetCore.JsonMergePatch.Tests.Builder.Json.Simple class for more examples

Morcatko.AspNetCore.JsonMergePatch.Tests.Builder.Json
public void UnitTest()
{
    var model = new Model();
    var patch1 = PatchBuidler.Build<Model>("{ integer: 1}");
    ...
    or
    ...
    var original = new Model();
    var patched = new Model() { Integer = 1};
    var patch2 = PatchBuilder.Build(original, patched);
}

Known issues/Not working

  • ModelState.IsValid is false when a required property is missing
  • Enums with [EnumMember(Value = "....")] attribute
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.0.5 27,825 3/24/2021
2.0.4 1,281 8/26/2020
2.0.3 665 8/7/2020
2.0.2 14,759 11/7/2019
2.0.1 1,607 11/3/2019
2.0.0 184,969 6/20/2019
2.0.0-beta10 1,053 5/27/2019
2.0.0-beta09 8,385 4/11/2019
2.0.0-beta08 554 4/2/2019
2.0.0-beta07 19,109 12/13/2018
2.0.0-beta06 2,634 12/7/2018
2.0.0-beta05 2,383 11/20/2018
2.0.0-beta04 50,021 9/7/2018
2.0.0-beta03 5,363 11/6/2017
2.0.0-beta02 814 11/3/2017
2.0.0-beta01 701 10/24/2017
2.0.0-alpha02 1,681 9/14/2017
1.0.0-alpha01 1,050 6/23/2017

Prerelease