Subject: | JSON:PP assumes it can recreate tied classes |
Date: | Fri, 24 Sep 2010 14:54:39 +1200 |
To: | bug-JSON [...] rt.cpan.org |
From: | Timothy Goddard <timg [...] catalyst.net.nz> |
We are encountering problems when attempting to serialise tied arrays in our
project. The piece of code this comes from is in array_to_json:
if (my $tie_class = tied @$obj) {
if ( $tie_class->can('TIEARRAY') ) {
$tie_class =~ s/=.+$//;
tie @res, $tie_class;
}
}
It looks like when serialising an array, it takes any class that the array is
tied to, then array_to_json attempts to tie the array of any extra parameters
it was given to that class. The class we tie to requires a reference to the
backing data and the tie call there tries to create a new instance of our
class without any arguments, triggering an error. These routines should not
assume that they can create new instances of the classes arrays and hashes
are tied to.
Since in all calls to array_to_json I could find only one parameter is passed,
it isn't apparent what the purpose of this code is. If this code is indeed
not used, I attach a patch which will remove it from the array_to_json and
equivalent hash_to_json routines. If it is used, maybe we can work out
another way to solve that which doesn't involve those assumptions. Happy to
help however I can.
Kind regards,
Tim Goddard
Message body is not shown because sender requested not to inline it.
Message body not shown because it is not plain text.