dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.82k stars 9.84k forks source link

Support for JSON Merge Patch (RFC 7386) #35237

Open Tiberriver256 opened 2 years ago

Tiberriver256 commented 2 years ago

Is your feature request related to a problem? Please describe.

Implementing JSON Merge Patch manually can be quite tricky but provides a simpler experience for API consumers.

Describe the solution you'd like

Currently there is built-in support for JSON Patch (RFC 6902) via JsonPatchDocument. Would love to also see an implementation of RFC 7386.

So no one has to wade through an RFC...

Given the following JSON representation:

{
  "name": "Joe",
  "email": "joe@example.com",
  "physicalAttributes": { "weight": 75, "height": 175 },
  "favoriteColors": ["blue", "red"]
}

These two will produce equivalent modifications:

JSON Patch

[
   { "op": "remove", "path": "/email" },
   { "op": "add", "path": "/favoriteColors/-", "value": "black" }
]

JSON Merge Patch

{
  "email": null,
  "favoriteColors": ["blue", "red", "black"]
}

Additional context

OData has an implementation of this spec via Delta but it was not designed to work with formatters other than OData.

Here are a couple of open-source implementations: https://www.strathweb.com/2013/01/easy-asp-net-web-api-resource-updates-with-delta/ https://github.com/Morcatko/Morcatko.AspNetCore.JsonMergePatch

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mitsha-microsoft commented 4 months ago

Hi, Our service uses PATCH primarily for a huge set of our APIs and having something built-in that handles RFC 7386 will help us greatly (otherwise we will need to roll out our own implementation or use a third party OSS package).