Skip Menu |

This queue is for tickets about the JSON CPAN distribution.

Report information
The Basics
Id: 64783
Status: resolved
Priority: 0/
Queue: JSON

People
Owner: Nobody in particular
Requestors: jordanhiller [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.50
Fixed in: (no value)



Subject: Impossible to convert blessed objects by stringifying
I would like certain objects to convert to JSON as their stringified values. For example: *DateTime::TO_JSON = sub { return overload::StrVal($_[0]); }; But it seems impossible thanks to this check (from JSON::PP): if ( overload::StrVal( $obj ) eq $result ) { encode_error( sprintf( "%s::TO_JSON method returned same object as was passed instead of a new one", ref $obj ) ); } The check seems rather arbitrary--why should you not be able to convert objects to JSON via their stringification? Thanks.
Resolved in JSON::PP 2.27105 and JSON 2.51. Thanks! On 2011-1月-14 金 16:34:05, jhiller wrote: Show quoted text
> I would like certain objects to convert to JSON as their stringified > values. For example: > > *DateTime::TO_JSON = sub { > return overload::StrVal($_[0]); > }; > > But it seems impossible thanks to this check (from JSON::PP): > > if ( overload::StrVal( $obj ) eq $result ) { > encode_error( sprintf( > "%s::TO_JSON method returned same object as was passed instead of a > new one", > ref $obj > ) ); > } > > The check seems rather arbitrary--why should you not be able to convert > objects to JSON via their stringification? > > Thanks.