Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we add support for TO_JSON #5

Open
dagolden opened this issue Oct 2, 2013 · 3 comments
Open

Should we add support for TO_JSON #5

dagolden opened this issue Oct 2, 2013 · 3 comments
Labels
Milestone

Comments

@dagolden
Copy link

dagolden commented Oct 2, 2013

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.

@dagolden
Copy link
Author

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)

@adamkennedy
Copy link
Member

+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?

@dagolden
Copy link
Author

dagolden commented May 3, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant