-
Notifications
You must be signed in to change notification settings - Fork 24
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
Wrong handling of empty objects in graph leading to wrongfully altered JSON #28
Comments
@raphaelstolt it could do a PR if we can find a way to correct it.. Could it be an option to wrap the payload in an Have the payload there as |
Yes that would be probably an approach. Feel free to send a PR (as I won't have time to look into this issue in the near future) and I'll merge it in time. |
I opened PR #29, seems to work nicely.. Sadly an approach with What you think? If it can be merged, I would appreciate a tag afterwards so we can update our dependencies ;-) |
Hello ;-)
First, thanks for your work! ;-)
We have a problem with your library in a use case with a big graph where the library wrongfully alters structures in the JSON (so differences between what i give in and what comes out after
apply()
) - sadly, even stuff not even explicitly targeted by the operations get changed.To show the wrong behavior, I created a test in my branch https://github.com/narcoticfresh/php-jsonpatch/tree/feature/emptyobject-conversion in commit narcoticfresh@c80a98b
Consider this document and operation:
The unit test will fail with:
As you can see,
emptyObj
is converted from\stdClass
toarray
. This is clearly a wrong behavior.It's obvious this problem comes from the fact that the json is decoded to
array
in theOperation
, thenjson_encode()
d again later - it's an old problem of PHP that{}
becomes anarray
in php, so on re-encoding it will wrongfully be[]
..Do you acknowledge this as bug? What could be a feasible way to correct it?
Thanks
The text was updated successfully, but these errors were encountered: