use JSON -convert_blessed_universally; use constant SERIALIZER => 'JSON'; *UNIVERSAL::TO_JSON = sub { my $b_obj = B::svref_2object( $_[0] ); return $b_obj->isa('B::HV') ? { %{ $_[0] } } : $b_obj->isa('B::AV') ? [ @{ $_[0] } ] : undef ; }; sub serialize{ my $self = shift; my $params = shift; my $json_obj = JSON->new->allow_nonref; my $serialize = $json_obj->allow_blessed->convert_blessed->encode( $params ); return $serialize; }