-
Notifications
You must be signed in to change notification settings - Fork 536
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
implement json patch RFC #69
Comments
Copying this from IRC so it doesn't get lost:
From serde_json's perspective I don't think we want to treat JSON patches as strings (i.e. dealing with from_str). If we just expose a type like We can expose @CryptArchy does that approach address your concern about needing "higher level bits of serde"? |
Yes, I think that all makes sense. I currently have a I'll look into using the general (de)serialization traits and how to implement them for the final The trickiest part so far has been meeting the demands of atomicity required for HTTP Patch semantics. The RFC isn't totally clear if that's required by the implementation itself or if the library user should respect those semantics. I opted to implement it so the library is easier to use. If any part of the patch fails, the whole thing has no effect. I could think of two obvious ways to do it:
I went with the second option, though more complicated, it seems like it should be more efficient (needs testing). As a nice side benefit, you can also return the undo stuck so every application of a patch gives you the commands to revert it yourself if there's a need from a higher level. It also creates a pleasing symmetry and flow in the execution. For example, |
Alright, I cleaned up things a little and pushed some code up to my fork. https://github.com/serde-rs/json/compare/master...CryptArchy:patch?expand=1 It's very rough as I'm still iterating on the concepts, but all the ops are in and working. I added one non-standard op
Currently, I'm thinking that the system could just convert |
I wrote my own implementation of both JSON Patch and JSON Merge Patch a while ago: https://github.com/idubrov/json-patch It tries to be optimal and modify Value in-place and revert changes if one of the operations fails. |
The json-patch crate looks great! I am happy pointing people to the implementation there -- I don't think we need this to be provided by serde_json. Thanks all! |
#41 (comment)
The text was updated successfully, but these errors were encountered: