Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

JSON::XS and blessings

by cshavit (Novice)
on Oct 13, 2015 at 19:41 UTC ( [id://1144744]=perlquestion: print w/replies, xml ) Need Help??

cshavit has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I have perl code running on apache. And the weirdest problem.

Consider this code snippet:

use JSON::XS; # # # my $json = "{\"has_more\": true}"; my $d = decode_json($json); my $e = encode_json($d);

You'd expect $e to equal $json. And if you ran it from a shell, it would be true.

I have two apache virtual hosts, running by the same Apache server on Ubunto. One of the servers always runs the code correctly. The other always dies on encode_json() with

"encountered object '1', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing)"

The problem does not happen if I use JSON::PP.

Could you please help me with fixing it? Even a hint.

Thanks!

Replies are listed 'Best First'.
Re: JSON::XS and blessings
by toolic (Bishop) on Oct 13, 2015 at 19:50 UTC
    Maybe you have an old, buggy version of JSON::XS on one of the hosts. Add this to the code to see what versions you're using:
    print "$JSON::XS::VERSION $]\n";
      Both servers run the latest. The printf prints 3.01 5.018002

      The thing that puzzles me if how could two virtual servers run *anything* different. Wouldn't "use ABC; load the same ABC on both?

      I'm asking because evidently *something* is different.

        true is the problem but I don't know why it's a problem. It roundtrips fine for me with 2.26. :|

        I'm asking because evidently *something* is different.
        Some other ideas for checking differences...
        use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper(\%ENV); system 'uname -a';

        The code is XS, which means that it requires a C compiler (which may be different).

Re: JSON::XS and blessings
by Anonymous Monk on Oct 16, 2015 at 08:03 UTC
    My guess is that you use JSON::XS from different ithreads, and JSON::XS says its not ithread-safe. It has code to go into super slow mode in that case, but that might not work, so it might not recognize the boolean package as "the" boolean package. It might be something else, but that came to my mind.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1144744]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found