-
Notifications
You must be signed in to change notification settings - Fork 16
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
Use structure in TO_JSON method when available #38
Comments
Is there any consensus among the various Perl 6 JSON modules as to calling such a method, and if yes, how to call it? Personally, I'd prefer |
In some of the Perl5 modules the documentation reads: "If $enable is true (or missing), then encode, upon encountering a blessed object, will check for the availability of the TO_JSON method on the object's class. If found, it will be called in scalar context and the resulting scalar will be encoded instead of the object." |
@moritz are you planning on incorporating the above patch into the module? |
@dannymk not before there is any consensus with, or at least data from, other Perl 6 JSON modules |
Where are we supposed to get this consensus from? |
From the authors of the other JSON-related p6 modules |
Not speaking as an author of a JSON module here, but certainly of some other Perl 6 modules. Rather than hard-coding a method name, I'd suggest something like .to-json( |
Another suggestion that feels even more Perl6ish to me would be something like this:
|
Perhaphs add a sub that takes an instance that can actually return a structure that only includes items that we want in the output:
see: https://stackoverflow.com/questions/53110521/perl6-class-to-json-exclude-properties/53120677#53120677
The text was updated successfully, but these errors were encountered: