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
Message body not shown because it is not plain text.