-
Notifications
You must be signed in to change notification settings - Fork 153
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
applyInPlace does not work when replace root path #188
Comments
While you are correct, the Jackson API (i.e. JsonNode) doesn't actually let you accomplish what you're trying to without some changes to the zjsonpatch API as well. To clarify:
In practice, this means applyInPlace cannot change the root node in many circumstances (replace object with scalar, replace scalar with object, replace object with array, replace array with object...). So we're left with the following options:
I don't really have a strong opinion here, since applyInPlace is an implementation feature of zjsonpatch, rather than anything specced out in the RFC. To my mind a replace on the root path should always result in a runtime exception with applyInPlace. Thoughts @ruiruige / @vishwakarma ? |
See #190 |
Thanks @holograph Thanks for the detailed breakdown and suggestions. I agree with your preference to reject patches that replace the root node outright when using applyInPlace. Raising a runtime exception in these cases feels like the most predictable and straightforward solution, and it keeps the behavior of applyInPlace aligned with its intended purpose. While the other options like "best faith" efforts or returning the replaced root node offer some flexibility, they might lead to inconsistent behavior or make the method more complex than necessary. Rejecting root replacements ensures that users are explicitly handling these scenarios, which I think is the right approach |
Expected Behavior
do replace when path is root while using applyInPlace
Actual Behavior
did nothing
input: {"throw", true}
diff: [
{
"op": "replace",
"path": "",
"value": {
"throw": false
}
}
]
applyInPlace does not replace anything. after I debug, I found InPlaceApplyProcessor does not change sourceNode when path is root:
Specifications
Library Version: 0.4.11
Language (e.g. Java 1.8, Scala, etc):Java 1.8
The text was updated successfully, but these errors were encountered: