Morcatko.AspNetCore.JsonMergePatch.SystemText
6.0.1
dotnet add package Morcatko.AspNetCore.JsonMergePatch.SystemText --version 6.0.1
NuGet\Install-Package Morcatko.AspNetCore.JsonMergePatch.SystemText -Version 6.0.1
<PackageReference Include="Morcatko.AspNetCore.JsonMergePatch.SystemText" Version="6.0.1" />
paket add Morcatko.AspNetCore.JsonMergePatch.SystemText --version 6.0.1
#r "nuget: Morcatko.AspNetCore.JsonMergePatch.SystemText, 6.0.1"
// Install Morcatko.AspNetCore.JsonMergePatch.SystemText as a Cake Addin #addin nuget:?package=Morcatko.AspNetCore.JsonMergePatch.SystemText&version=6.0.1 // Install Morcatko.AspNetCore.JsonMergePatch.SystemText as a Cake Tool #tool nuget:?package=Morcatko.AspNetCore.JsonMergePatch.SystemText&version=6.0.1
JSON Merge Patch support for ASP.NET Core
- Morcatko.AspNetCore.JsonMergePatch (ASP.NET Core 2.x)
- Morcatko.AspNetCore.JsonMergePatch.NewtonsoftJson (ASP.NET Core 3+)
- Morcatko.AspNetCore.JsonMergePatch.SystemText (ASP.NET Core 3+)
- Morcatko.AspNetCore.JsonMergePatch.Document (ASP.NET Core 3+ - base package)
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:
var mergePatch = new object() {
"Weapon": "Knife"
}
Resulting C# object:
var newObject = new Model() {
Name = "James Bond"
Age = "45"
Weapon = "Knife"
}
How to
See 2.1-testApp
, 3.0 testApp
or 6.0/testApp
for sample
- Install nuget (Use JsonMergePathch version same as your .NET) .
- ASP.NET Core 2.x Morcatko.AspNetCore.JsonMergePatch
- ASP.NET Core 3+ (Newtonsoft.Json) Morcatko.AspNetCore.JsonMergePatch.NewtonsoftJson
- ASP.NET Core 3+ (System.Text) Morcatko.AspNetCore.JsonMergePatch.SystemText nuget
- Add to your startup class
using Morcatko.AspNetCore.JsonMergePatch;
public void ConfigureServices(IServiceCollection services)
{
...
services
.AddMvc() // or .AddMvcCore()
//.AddJsonMergePatch(); // 2.x
//.AddNewtonsoftJsonMergePatch(); // 3+ (Newtonsoft.Josn)
//.AddSystemTextJsonMergePatch(); // 3+ (System.Text)
...
}
- 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.ApplyToT(backendModel)
- Swagger config (optional)
copy & paste this class into your app
- 2.x - https://github.com/Morcatko/Morcatko.AspNetCore.JsonMergePatch/blob/master/src/2.1-testApp/JsonMergePatchDocumentOperationFilter.cs
- 3+ - https://github.com/Morcatko/Morcatko.AspNetCore.JsonMergePatch/blob/master/src/6.0-testApp/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 tests in ...Builder.Json.Simple
class for more examples
Morcatko.AspNetCore.JsonMergePatch.Tests.Builder.Json
public void UnitTest()
{
var model = new Model();
var patch1 = PatchBuilder.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 | net6.0 is compatible. 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. |
-
net6.0
- Morcatko.AspNetCore.JsonMergePatch.Document (>= 6.0.1)
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 |
---|---|---|
6.0.1 | 5,502 | 8/19/2024 |
6.0.0 | 141,857 | 4/29/2022 |
6.0.0-alpha01 | 988 | 1/21/2022 |
3.0.7 | 71,677 | 3/24/2021 |
3.0.6 | 13,523 | 11/16/2020 |
3.0.5 | 3,824 | 9/30/2020 |
3.0.4 | 15,253 | 8/26/2020 |
3.0.3 | 921 | 8/7/2020 |
3.0.2 | 4,750 | 6/3/2020 |
3.0.1 | 25,507 | 3/24/2020 |
3.0.0 | 2,404 | 2/18/2020 |
3.0.0-Release0.0 | 283 | 11/27/2019 |