A generator that creates a JSON Patch Document from comparing two objects
Work in progress
If you faced any problems using this lib please feel free to create an issue. If the library was useful for you - give it a star. This way I'll be able to know that it's useful for someone and try to find time to continue working on it. All contributions are welcome
PM> Install-Package JsonPatchGenerator.AspNetCore
> dotnet add package JsonPatchGenerator.AspNetCore
PM> Install-Package JsonPatchGenerator.Marvin.JsonPatch
> dotnet add package JsonPatchGenerator.Marvin.JsonPatch
Everything is simple:
var patchGenerator = new JsonPatchDocumentGenerator();
var jsonPatchDocument = patchGenerator.Generate(first, second);
Add this line to the ConfigureServices
method of your Startup.cs
:
services.AddJsonPatchGenerator();
Add IJsonPatchGenerator<IJsonPatchDocument>
as a dependency when you need it.
readonly IJsonPatchGenerator<IJsonPatchDocument> _jsonPatchGenerator;
public HomeController(IJsonPatchGenerator<IJsonPatchDocument> jsonPatchGenerator)
{
_jsonPatchGenerator = jsonPatchGenerator;
}
Now you can use it:
var jsonPatchDocument = _jsonPatchGenerator.Generate(first, second);