Skip to content
This repository has been archived by the owner on Apr 20, 2020. It is now read-only.

[Feature Request] Add json serialization #2

Closed
gadfly361 opened this issue Sep 10, 2019 · 2 comments
Closed

[Feature Request] Add json serialization #2

gadfly361 opened this issue Sep 10, 2019 · 2 comments

Comments

@gadfly361
Copy link

Thanks for sharing this library! I have definitely been wanting to use something like this.

Is it possible to add json serialization to the generated data class?

My specific use-case is that I'd like to use json_serializable. To use it, I'd need to add some boilerplate (toJson and fromJson) to the generated data class; however, the generated data class can't be edited by hand.

@MarcelGarus
Copy link
Owner

MarcelGarus commented Sep 12, 2019

Hmm good question. I guess we could try to add a meta-anmotation like
@Annotation(JsonSerializable()) to the mutable class to then add the actual annotation @JsonSerializable() to the generated class.
But I'm not even sure you can add annotations in generated files...
Also, this issue doesn't have the highest priority right now, so it'll take some time until I evaluate/implement this. Of course you're welcome to contribute to the project, if you want to!
In the meantime, you can of course add @JsonSerializable to the mutable class and use User.toMutable().toJson() and User.fromMutable(MutableUser.fromJson(json)) although this is more boilerplate.
Oh and also, take into consideration that static extension methods are actively being worked on by the Dart team right now, so soon you'll be able to define User.toJson() => this.toMutable().toJson() in the original file.

@gadfly361
Copy link
Author

@MarcelGarus Thanks for the detailed response! I am going to close this in favor of tracking #4

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

No branches or pull requests

2 participants