Skip to content
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

add "create" operation #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hnguyen08
Copy link

I'd like to extend JSON Patch and add a new "create" operation. It is exactly like "add", except it will not replace an existing value at the requested path. It will be useful in situations in where a client wants to ensure that they are not overwriting a value set by another client.

This was a suggestion from an email thread with the RFC6902 authors:

I think you've got it right; you can't do it in a fine-grained way with json-patch. Of course, you could use HTTP conditionals (e.g., If-Match), but that's more coarse-grained.
If you want to do this right now, I think the best thing to do would be to define a new operation and then use a new media type to differentiate between it and JSON Patch.
I'd be interested in starting a new version of json patch if we can get enough experience with this one to make it worthwhile...

Although it deviates from the RFC, I think it would be useful for others to use, perhaps in a custom JsonPatch implementation as you mentioned in #9.

Let me know what you think!

@fge
Copy link
Collaborator

fge commented Mar 24, 2014

I agree that this operation is nice, but indeed I'd like to keep RFC 6902 compatibility, which means I'll need to refactor and make JsonPatch abstract... That'll be for a 2.0 version.

As to the patch itself, it looks good, but I'd suggest the following changes:

  • renaming AddableOperation to AdditionOperation,
  • add a boolean to its protected constructor which would be true if we wanted to overwrite object members,
  • modify the code of addToObject() so that it exploit this boolean to know whether it should overwrite.

@hnguyen08
Copy link
Author

Thanks! I'll make an update using your suggestions.

@hnguyen08
Copy link
Author

Squashed

@hnguyen08
Copy link
Author

Updated to make overwriteExisting final. Let me know what you think

@fge
Copy link
Collaborator

fge commented Mar 31, 2014

Excellent! Now I need to find the time to work on that project again... Right now I'm busy with json-schema-*...

@hnguyen08
Copy link
Author

Thanks, I'll keep an eye out for any updates.

stephanedaviet pushed a commit to stephanedaviet/json-patch that referenced this pull request Apr 6, 2019
BartekGravity pushed a commit to gravity9-tech/json-patch-path that referenced this pull request Jun 20, 2023
…son_pointer_double_slashes

#807 JsonPointer double slashes validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants