On Tue Nov 18 15:13:41 2014, ETHER wrote:
Show quoted text
I'd get rid of -convert_blessed_universally but so far I haven't been able to figure out how to get JSON or any other JSON serializer to work with blessed objects. To reduce the problem to minimal code, consider the following example which uses a blessed hash (CGI which is built-in). The first example, using -convert_blessed_universally, serializes the object to a JSON hash structure:
#!/usr/bin/perl -w
use strict;
use CGI;
use JSON qw{to_json -convert_blessed_universally};
my $cgi = CGI->new();
print to_json($cgi, {convert_blessed=>1}), "\n";
This next example, without -convert_blessed_universally, just returns null. The code is adapted straight from the JSON docs:
#!/usr/bin/perl -w
use strict;
use CGI;
use JSON;
my $cgi = CGI->new();
print JSON->new->allow_blessed->convert_blessed->encode( $cgi ), "\n";
I've tried other JSON modules but basically run into the same problem: they won't just serialize a blessed hash or array.
I don't want to add a TO_JSON method in Log::QnD because it doesn't really address the problem if nested structures are in the QnD object.
So, I'll gladly make the change if someone can provide the code. I'll be happy to use JSON or another JSON serializer.
-Miko