Reputation: 2417
I was looking at this thread: https://groups.google.com/a/dartlang.org/forum/#!topic/misc/0pv-Uaq8FGI but still cannot find a solution for what I would like to have on the client side (possible on the server as well).
I imagine there should be a way to provide a standard format for data structure that is represented as JSON object in JS land (for example json schema or yaml or whatever) that could be used as input to generate Dart classes that contain the fromJSON constructor and toJSON method (possible some checks as well for the data ranges) that the developer can then extend if additional logic is needed over the data coming over the wire.
I do not want to use mirrors if possible, instead the classes should be statically generated (i.e. run a tool -> get the class(es) to match the latest schema/input).
Can you point me to the right direction?
Thanks.
Upvotes: 7
Views: 1276
Reputation: 2579
There is a great package called json_serializable
on pub that creates serializers for your models via code generation.
You can customize the generated code via annotations or you can just modify the generated code by hand.
Upvotes: 1