[Discussion] using a modelling library
ahmednfwela opened this issue · comments
Description
the current library behavior relies on generating models manually (including serialization, deserialization, copyWith, etc...)
this is very error prone
Alternatives
we can use build_runner to automatically generate serialization/deserialization bindings, similar to c# using reflection in runtime, instead this being at compile time.
here are some libraries for this:
- https://pub.dev/packages/json_serializable (very basic serialization only)
- https://pub.dev/packages/freezed (advanced, on top of json_serializable, adds copyWith, and equality)
- https://pub.dev/packages/dart_mappable (advanced, adds support for polymorphism, can be used on top of freezed or without)
we can even take it a step further and generate the http bindings via something like
Hi @ahmednfwela
Indeed, if we can automate some checking, it will be amazing.
But I would like to understand the possible pros and cons of adopting such a solution, especially in terms of maintenance and userland breaking changes.
Also, can we implement something like this in small steps, (incrementally) instead of creating a big-bang PR?
all the heavy lifting is done at generation time (before compile time) and at runtime everything is practically the same.
I will create some test PRs to see the best solution
Do you think this subject is still relevant @ahmednfwela?
yes I am testing out this package https://pub.dev/packages/dart_json_mapper which seems like the best candidate for now
Closing this issue now, since we started using json_serializable in the latest version