k-paxian / dart-json-mapper

Serialize / Deserialize Dart Objects to / from JSON
https://pub.dev/packages/dart_json_mapper
Other
400 stars 33 forks source link

Introduce converter for `MaterialColor` class in Flutter adapter #183

Open DetachHead opened 2 years ago

DetachHead commented 2 years ago
E/flutter (24684): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: It seems your class 'MaterialColor' has not been annotated with @jsonSerializable

i'm coming from the json_serializable package where these errors would instead occur when running build_runner

k-paxian commented 2 years ago

That's primarily because json_serializable is using static approach where you have literally all your code to be potentially used is generated in advance for you. dart_json_mapper instead, uses mostly dynamic approach, where you don't have most of the code generated for you in advance, this code does not exists until you actually use it in runtime. Technically it's difficult to oversee and predict beforehand which classes you would like to use until you annotate them explicitly or register them with an adapter.

There is an ignoreUnknownTypes option for you to ignore unknown types. Example is here

Or we could extend Flutter adapter to support this class for you seamlessly, what do you think?

DetachHead commented 2 years ago

Or we could extend Flutter adapter to support this class for you seamlessly, what do you think?

oh, i wasn't even aware there was a flutter adapter. i just tried it out and it seems to work fine with the Color class i'm using (i think i accidentally imported MaterialColor when i first raised this tho, i'm not actually using that class though it would probably be a good idea to support it)