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

Add a toJson method for serialization. #3

Merged
merged 2 commits into from
Mar 15, 2019
Merged

Add a toJson method for serialization. #3

merged 2 commits into from
Mar 15, 2019

Conversation

yohom
Copy link
Contributor

@yohom yohom commented Mar 14, 2019

Fixes #2.

Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! 👍
This looks good to me apart from that small dynamic change. I'm also wondering if it makes sense to also generate a .fromJson factory, similar to the fromData factory. But feel free to skip that if you don't need it, I can also add it myself.

@@ -94,6 +97,17 @@ class DataClassWriter {
buffer.write(');}\n');
}

void _writeToJson(StringBuffer buffer) {
buffer.write('Map<String, Object> toJson() {\n return {');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a personal thing, but I'd prefer this to return Map<String, dynamic>, it feels more appropriate as that's also what would be returned by json.decode.
Unless you have a better argument in favor of Object, of course :)

@simolus3 simolus3 merged commit e7cb0cb into simolus3:develop Mar 15, 2019
@simolus3
Copy link
Owner

Thanks again for your contribution 👍

@aidooyaw1992 aidooyaw1992 mentioned this pull request Sep 24, 2019
@abhaykd22 abhaykd22 mentioned this pull request Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants