Skip to content

JSON Patch replace entire object in root path throws error #17927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fabich opened this issue Dec 17, 2019 · 2 comments
Closed

JSON Patch replace entire object in root path throws error #17927

fabich opened this issue Dec 17, 2019 · 2 comments
Labels
affected-very-few This issue impacts very few customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. feature-json-patch ✔️ Resolution: Duplicate Resolved as a duplicate of another issue severity-minor This label is used by an internal tool Status: Resolved
Milestone

Comments

@fabich
Copy link

fabich commented Dec 17, 2019

Describe the bug

JSON Patch implementation does not work as expected when trying to replace entire object.
Error: The target location specified by path segment '' was not found.

To Reproduce

input:

{
  "flightnumber": "3523",
  "dep": "YUL",
  "dest": "YYZ"
}

patch:

[{
"op": "replace",
"path": "",
"value": {
  "flightnumber": "111",
  "dep": "YYC",
  "dest": "YUL"}
}
]

output:

{
  "flightnumber": "111",
  "dep": "YYC",
  "dest": "YUL"
}

Test runs successful with json8 (https://github.com/sonnyp/JSON8):
https://json8.github.io/patch/demos/apply/

code example:

var flight = new FlightPatchDTO{...};
var patchDoc = new JsonPatchDocument<FlightPatchDTO>();
patchDoc.Replace(x => x, flight);

....

Error:

Microsoft.AspNetCore.JsonPatch.Exceptions.JsonPatchException : The target location specified by path segment '' was not found.
   at Microsoft.AspNetCore.JsonPatch.Internal.ErrorReporter.<>c.<.cctor>b__1_0(JsonPatchError error)
   at Microsoft.AspNetCore.JsonPatch.Adapters.ObjectAdapter.Replace(Operation operation, Object objectToApplyTo)
   at Microsoft.AspNetCore.JsonPatch.Operations.Operation`1.Apply(TModel objectToApplyTo, IObjectAdapter adapter)
   at Microsoft.AspNetCore.JsonPatch.JsonPatchDocument`1.ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter)
   at Microsoft.AspNetCore.JsonPatch.JsonPatchDocument`1.ApplyTo(TModel objectToApplyTo)

Further technical details

  • ASP.NET Core version: netcoreapp2.2
@fabich fabich changed the title JSON Patch replace entire object JSON Patch replace entire object in root path throws error Dec 17, 2019
@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Dec 17, 2019
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Dec 17, 2019
@mkArtakMSFT
Copy link
Member

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@javiercn javiercn added affected-very-few This issue impacts very few customers severity-minor This label is used by an internal tool labels Oct 9, 2020
@javiercn javiercn added the bug This issue describes a behavior which is not expected - a bug. label Oct 9, 2020 — with ASP.NET Core Issue Ranking
@TanayParikh
Copy link
Contributor

Thanks, closing as duplicate of #25942

@TanayParikh TanayParikh added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Oct 19, 2021
@ghost ghost added the Status: Resolved label Oct 19, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 19, 2021
@amcasey amcasey added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-very-few This issue impacts very few customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. feature-json-patch ✔️ Resolution: Duplicate Resolved as a duplicate of another issue severity-minor This label is used by an internal tool Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants