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
Json Patch model binding weirdness #146
Comments
Interesting scenario you've found. From the docs I'd expect that ASP.Net would just do the same deserialization that you're doing in the manual one. Would you work up a minimal solution that replicates this, please? I want to make sure that what I debug is the same as what you're seeing. Thanks for the report. |
The MS docs for how to do JSON Patch suggest using Newtonsoft and System.Text.Json 🤦 I wonder if this is what's happening: ASP.Net reads that it's a PATCH call and tries to deserialize into whatever Newtonsoft has provided. |
Here you go https://github.com/Jetski5822/JsonPatchBug146 Something weird for you, it works under IISExpress... but NOT Kestrel. If you clone, build, and then flip it to be Kestrel using Postman do... PATCH to http://localhost:5000/patchme
So weird.!!! |
Hmm, In here https://github.com/gregsdennis/json-everything/blob/master/JsonPatch/PatchOperation.cs#L20 Shouldnt Op and Path be the only non nullable objects? with Value and From being nullable objects? based on here http://json.schemastore.org/json-patch |
Having those non-null resolved some processing issues I had while enabling nullable reference types in the lib. I do have it nullable in a DTO in the converter defined in the same file, toward the bottom. |
Well, it's definitely deserializing the patch properly. I removed the nuget package and just imported the projects. This is just before returning from json-everything/JsonPatch/JsonPatch.cs Line 90 in 62bc62d
Something's happening between the deserialization and entering the controller. Maybe ASP.Net is doing some validation, though I'm not sure what would be instructing it to do so. |
Okay. Found what might be causing it and a workaround for you. Update Startup.cs: // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages()
.AddMvcOptions(options => options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true);
} What's odd is that the app doesn't have |
Looked at this a bit today. I'm still not sure where that error message is being generated, so I don't know how to fix it other than the above. |
Nice one Greg, I'll give it a go - I'll also pull your code to my sln and see if I can get it to work. It's weird that it works fine in IIS express though :/ |
The validation engine is saying that Interestingly, I'm using ... I still have no clue where that error message is coming from. |
Okay. Try v1.0.6. |
It works!!! Nice one - thanks for the fast turn around. |
Environment
How can I help you today?
I have some patch JSON:
When I call and MVC endpoint like so; it works.
Patch is populated, world is good.
If I change it over to this;
I get the following;
Any thoughts on how I can fix this? as im a little confused :D
The text was updated successfully, but these errors were encountered: