-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
JsonPatchDocument .ApplyTo(...)
raises JsonPatchException
for unknown Properties instead of transparently mapping them to JsonExtensionData
#57711
Comments
.ApplyTo(...)
raises JsonPatchException
for unknown Properties instead of mapping them to JsonExtensionData
.ApplyTo(...)
raises JsonPatchException
for unknown Properties instead of transparently mapping them to JsonExtensionData
@hf-kklein Thanks for reporting this issue! The Microsoft.AspNetCore.JsonPatch package doesn't support System.Text.Json yet, so I don't expect the use of STJ's There is currently an open-source version of the JsonPatch support via System.Text.Json that you can use: https://github.com/Havunen/SystemTextJsonPatch Perhaps try that and see if it resolves your issue? |
I created a workaround for anyone else having this issue: https://github.com/Hochfrequenz/JsonPatchDocumentExtensionDataAdapter It's probably neither as pretty nor as elegant as it could be, but works in my tests. |
@hf-kklein Does your implementation assume that a user is mixing Newtonsoft.Json and System.Text.Json in their application to support the full end-to-end? I would've expected your implementation to extend on the third-party library mentioned above but it seems to build on the built-in implementation which uses Newtonsoft.Json at the moment... |
Yes, it's built on top of the existing implementation - regardless of whether that's based on Newtonsoft or STJ. My intention was to make it as least "invasive" as possible. Users just need to add few lines of code at those places where patches shall be applied to STJ extension data annotated properties. It does not enhance any existing middleware or model binding under the hood. As I said: It's not as elegant or well designed as it could be, but it works. |
Is there an existing issue for this?
Describe the bug
If a property is annotated with the
[System.Text.Json.Serialization.JsonExtensionData]
attribute, I expect theJsonPatchDocument.ApplyTo(...)
method to map unknown paths to the respective property.Instead (actual behaviour), an
Microsoft.AspNetCore.JsonPatch.Exceptions.JsonPatchException
is raised.Expected Behavior
Unmapped paths in a JsonPatchDocument should be mapped (transparently) to the JsonExtensionData property.
By "transparently" I mean, that the client sending the patch to the server doesn't need to be aware of the ExtensionData property.
Steps To Reproduce
Exceptions (if any)
No response
.NET Version
8
Anything else?
No response
The text was updated successfully, but these errors were encountered: