Perl-Toolchain-Gang/YAML-Tiny

Should we add support for TO_JSON

Opened this issue · 3 comments

Unlike full YAML, YAML::Tiny doesn't allow objects. In this way, it has the same constraint as JSON. There is already a well-accepted convention for objects serializing to JSON by providing a TO_JSON method. If YAML::Tiny checked for TO_JSON on objects before dying, we could take advantage of existing methods and conventions.

This would take very little code and would make it much easier for people to serialize data structures that might have string-like objects, including versions, paths, datetimes, etc.

ping.

I'd like to get a decision taken so we can ship a YAML::Tiny 2.00 before January (Perl contentious code change freeze)

+1 on adding support (it assists the migration of the toolchain from YAML to JSON).
-0 on making it the default option, should it be an option passed to the ->write and/or dump methods?

$yaml->write($filename, convert_blessed => 1)
$yaml->write_string(convert_blessed => 1)

Since Dump takes a list already and exists for compatibility with YAML I would imagine we don't change it.

Is this a reasonable approach?

Sereal is supporting the Types::Serialiser protocol with FREEZE/THAW (introduced for CBOR and JSON::XS version 3). It seems reasonably sane and flexible and with those serializers supporting it may become a defacto standard we could follow instead of the limiting, one-way, TO_JSON approach.

It's not entirely Tiny, though, as it would require support for tags, I think.