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
Option for stringification of objects #37
Comments
I agree. I've tried both variants back and forth, and there needs to be an option. |
👍 I would really like to use that option. |
The counter argument is explained here: https://www.youtube.com/watch?v=Gzx6KlqiIZE&feature=youtu.be serializers who allow deserialization of objects, and JSON and Data::MessagePack are the only ones currently who do not, are unsafe. |
This feature does not allow for deserialization of objects, it is only an additional way to serialize them; when deserialized, they will still always be strings. |
Seems like a nice to have :) |
👍 Being able to fallback on stringification of an object for serialization would be more useful than just getting |
👍 |
Can somebody come up with a testcase please? This test works ok:
|
This issue is regarding stringification of objects, booleans are not a problem (anymore). |
So we'll add the option |
Here's a basic test case:
EDIT: changed to explicit stringification test |
works ok with new Mojo, but fails with old See GH #37
Mojo does not store their booleans as JSON::PP::Boolean as everybody else does. See GH #37
See branch |
I couldn't get the AMAGIC call yet working, so I'll postpone this feature. |
I'll keep the name |
👍 |
New feature to optionally stringify perl objects when encoding to json. See GH #37
fixes for older versions: 5.12, <5.18 and 5.6 >5.18 the stash is overloaded, <5.18 the sv. we got an already unrefed sv in encode_stringify. temp. RV it to call AMG_CALLunary Fixes GH #37
The feature works now >5.8.
or
Without embedded doubel-quotes it would allow to stringify into native js primitives, which might be a wanted feature. So I enforce |
Agreed, enforcing |
with 5.8 we need to rebless the rv to set AMG. For safety recalc the overload magic methods also. Fixes GH #37 for 5.8
All tests pass, I'll merge it now to master |
EDIT: Moved to new issue #46 |
Based on the behavior of Mojo::JSON and some discussion on dealing with references there, this is a suggestion for an option to stringify blessed references instead of encoding to null or throwing an exception, when no TO_JSON method is found. Perhaps stringify all objects such as Mojo::JSON does currently (better for debugging), or another possibility is to detect if the object has overload defined. Either way would make Cpanel::JSON::XS compatible with Mojo::JSON for structures which contain e.g. Mojo::ByteStream objects, or DateTime objects.
The text was updated successfully, but these errors were encountered: