Closed amarwadi closed 7 years ago
Are you setting the request's Content-Type as "application/json-patch+json"?
I had this same issue. Make sure that the JSON body of your request is formatted correctly. I was using RestSharp, which serializes using a formatter that doesn't respect the [SerializeAs] attributes on JsonPatchDocument. Using fiddler I was able to see what was being passed in the request body and with Insomnia I could confirm that it didn't work. By serializing with Newtsoft.Json, I got out put that looked like the json patch RFC.
Closing issue as it seems to be solved. If you experience additional problems, feel free to reopen.
How this was resolved? I have the same problem.
I've tried adding
config.Formatters.JsonFormatter.SupportedMediaTypes.Add( new MediaTypeHeaderValue("application/json-patch+json"));
And both with simple "application/json" but I always have a null object on server.
Here's signature of my api method
public IHttpActionResult PatchEntity(int id, [FromBody]JsonPatchDocument<Entity> entity)
and here my simple JSONPatch sent by restlet client.
{ "op": "replace", "path": "/seconds", "value": "12" }
Any help on this?
Thanks, Daniele
I solved by myself. A correct JSONPatch body must contain an array of operations. Changing my request in:
[{ "op": "replace", "path": "/seconds", "value": "12" }]
works like a charm.
Daniele
Thanks. I was doing same mistake
Bad code { { "op": "replace", "path": "/name", "value": "Updated - Central Park" } }
Fixed code [ { "op": "replace", "path": "/name", "value": "Updated - Central Park" } ]
Hello, Is there anything special I need to do other than adding the Nuget Package and using the JsonPatchDocument on the [FromBody] attribute for the HttpPatch methods on Web API? For some reason, no matter what I do, I always get a null object. Here's how my call looks like:
I am using ASP.NET Web API (not on ASP.NET Core). Any help would be appreciated.
Anup