On Feb 15, 2011, at 5:08 AM, Jiří Pavlovský wrote: > Hello, > > I'm pondering what way to use to serialize my Moose classes to JSON. I've > have been looking to MooseX::Storage but it seems it cannot handle more than > basic attribute types. Just the very first class I tried: "Cannot handle type > constraint (MooseX::Types::URI::Uri)" > There seems to be a way to add custom handlers, but the documentation is > scarce. > I also tried the MooseX::Storage::Format::JSONpm, but the result is the same. > > Or should I go with plain JSON module and add the TO_JSON method to my > classes? > > Thank you, > Jiri
Sorry, this feature never really got properly documented, but patches are always welcome, and doc patches are especially welcome. What you want to do is to look at the methods listed here: http://search.cpan.org/~bobtfish/MooseX-Storage-0.29/lib/MooseX/Storage/Engine.pm#Type_Constraint_Handlers And take a look at this test: http://cpansearch.perl.org/src/BOBTFISH/MooseX-Storage-0.29/t/006_w_custom_type_handlers.t You will need to write a custom inflate/deflate routine for any type that MooseX::Storage cannot recognize, which is basically anything that is not a Moose class or a native Perl data structure. - Stevan
