1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
use Test::More;
BEGIN {
$ENV{PERL_JSON_BACKEND} = 0;
eval "require JSON;";
if ($@) {
plan skip_all => "JSON required for testing interop";
exit 0;
}
eval "require JSON::XS;";
if ($@) {
plan skip_all => "JSON::XS required for testing interop";
exit 0;
} else {
plan tests => 4;
}
}
use JSON (); # limitation: for interop with JSON load JSON before Cpanel::JSON::XS
use Cpanel::JSON::XS ();
my $boolstring = q({"is_true":true});
my $js;
{
require JSON::XS;
my $json = JSON::XS->new;
$js = $json->decode( $boolstring );
# bless { is_true => 1 }, "JSON::PP::Boolean"
}
my $cjson = Cpanel::JSON::XS->new->allow_blessed;
is($cjson->encode( $js ), $boolstring) or diag "\$JSON::XS::VERSION=$JSON::XS::VERSION";
{
local $ENV{PERL_JSON_BACKEND} = 'JSON::PP';
my $json = JSON->new;
$js = $json->decode( $boolstring );
# bless { is_true => 1 }, "JSON::PP::Boolean"
}
is ($cjson->encode( $js ), $boolstring) or diag "\$JSON::VERSION=$JSON::VERSION";
{
local $ENV{PERL_JSON_BACKEND} = 'JSON::XS';
my $json = JSON->new;
$js = $json->decode( $boolstring );
# bless { is_true => 1}, "Types::Serialiser"
}
is($cjson->encode( $js ), $boolstring) or diag "\$JSON::VERSION=$JSON::VERSION";
# issue18: support Types::Serialiser without allow_blessed (if JSON-XS-3.x is loaded)
$js = $cjson->decode( $boolstring );
is ($cjson->encode( $js ), $boolstring) or diag(ref $js->{is_true});
|