Skip Menu |

This queue is for tickets about the JSON CPAN distribution.

Report information
The Basics
Id: 16602
Status: resolved
Priority: 0/
Queue: JSON

People
Owner: Nobody in particular
Requestors: yann [...] cyberion.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Add an option to ask the objects to convert themselves + refactoring
Hi, Please find attached a patch to allow the objects to convert themselves to JSON. To have this to work, objects would have to have a toJson() method, and the user would have to enable the new 'selfconvert' or $JSON::SelfConvert option. This is handy because it avoids nasty tricks of locally overriding _valueToJson (or valueToJson depending on the version). Please note also : - I've taken the liberty to factor _toJson within the Converter (hashToJson and arrayToJson). - This feature relies on Scalar::Util::blessed (to detect if the $obj is blessed) - You should also notice the test suite for this feature included in the patch Thanks for your hard work ! Yann Kerherve Six Apart
Download patch_json
application/octet-stream 9.5k

Message body not shown because it is not plain text.

Subject: Re: Add an option to ask the objects to convert themselves + refactoring
Thanks to your patch. I am willing to add the function to new version (by the end of this month). But I might not accept the refactoring by _toJson because the speed decreases by about 10% when it is done in my test. I'll examine it a little more. Regards, Makamaka