1 2use strict; 3use Test::More; 4BEGIN { plan tests => 3 }; 5 6BEGIN { $ENV{PERL_JSON_BACKEND} = 0; } 7 8use JSON -convert_blessed_universally; 9 10 11my $obj = Test->new( [ 1, 2, {foo => 'bar'} ] ); 12 13$obj->[3] = Test2->new( { a => 'b' } ); 14 15my $json = JSON->new->allow_blessed->convert_blessed; 16 17is( $json->encode( $obj ), '[1,2,{"foo":"bar"},"hoge"]' ); 18 19$json->convert_blessed(0); 20 21is( $json->encode( $obj ), 'null' ); 22 23$json->allow_blessed(0)->convert_blessed(1); 24 25is( $json->encode( $obj ), '[1,2,{"foo":"bar"},"hoge"]' ); 26 27 28package Test; 29 30sub new { 31 bless $_[1], $_[0]; 32} 33 34 35 36package Test2; 37 38sub new { 39 bless $_[1], $_[0]; 40} 41 42sub TO_JSON { 43 "hoge"; 44} 45 46