Morcatko.AspNetCore.JsonMergePatch
2.0.0-beta09
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.
See the version list below for details.
dotnet add package Morcatko.AspNetCore.JsonMergePatch --version 2.0.0-beta09
NuGet\Install-Package Morcatko.AspNetCore.JsonMergePatch -Version 2.0.0-beta09
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-beta09" />
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-beta09
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Morcatko.AspNetCore.JsonMergePatch, 2.0.0-beta09"
#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-beta09&prerelease // Install Morcatko.AspNetCore.JsonMergePatch as a Cake Tool #tool nuget:?package=Morcatko.AspNetCore.JsonMergePatch&version=2.0.0-beta09&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
- Install Morcatko.AspNetCore.JsonMergePatch nuget
- Add to your startup class
using Morcatko.AspNetCore.JsonMergePatch;
public void ConfigureServices(IServiceCollection services)
{
...
services
.AddMvc() // or .AddMvcCore()
.AddJsonMergePatch();
...
}
- Use in your controller
using Morcatko.AspNetCore.JsonMergePatch;
[HttpPatch]
[Consumes(JsonMergePatchDocument.ContentType)]
public void Patch([FromBody] JsonMergePatchDocument<Model> patch)
{
...
patch.ApplyTo(backendModel);
...
}
You can apply a patch to a different Type (be carefull, all C# static typing is ignored) - see #16 for more details.
BackendModel backendModel;
JsonMergePatch<DtoModel> patch;
patch.ApplyTo(backendModel)
- 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>();
});
Options
services
.AddMvc()
.AddJsonMergePatch(o => ....)
- bool EnableDelete - Deletes items when target object is Dictionary and patched value is null
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 | Versions 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.
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc.Formatters.Json (>= 2.0.0)
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 | 34,068 | 3/24/2021 |
2.0.4 | 1,334 | 8/26/2020 |
2.0.3 | 688 | 8/7/2020 |
2.0.2 | 14,806 | 11/7/2019 |
2.0.1 | 1,630 | 11/3/2019 |
2.0.0 | 196,019 | 6/20/2019 |
2.0.0-beta10 | 1,087 | 5/27/2019 |
2.0.0-beta09 | 8,846 | 4/11/2019 |
2.0.0-beta08 | 580 | 4/2/2019 |
2.0.0-beta07 | 19,515 | 12/13/2018 |
2.0.0-beta06 | 2,776 | 12/7/2018 |
2.0.0-beta05 | 2,403 | 11/20/2018 |
2.0.0-beta04 | 53,073 | 9/7/2018 |
2.0.0-beta03 | 5,402 | 11/6/2017 |
2.0.0-beta02 | 835 | 11/3/2017 |
2.0.0-beta01 | 724 | 10/24/2017 |
2.0.0-alpha02 | 1,713 | 9/14/2017 |
1.0.0-alpha01 | 1,081 | 6/23/2017 |
Prerelease