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.