-
Notifications
You must be signed in to change notification settings - Fork 371
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
Conversation
There was a problem hiding this 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 {'); |
There was a problem hiding this comment.
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 :)
Thanks again for your contribution 👍 |
Fixes #2.