Thoughts on Marshalling and Unmarshalling in Zydeco
Prompted by a recent question on PerlMonks, I've been thinking a bit recently on marshalling and unmarshalling Perl objects. If you're happy using Data::Dumper's format, then it's trivial, but today we're looking at JSON.
If you just want to encode your objects as JSON, that's very easy. Just add a TO_JSON
method to all your classes. This can be done in a role to eliminate duplication, and in most cases can be as simple as:
The difficulty comes in going the other direction.