dart-json-mapper icon indicating copy to clipboard operation
dart-json-mapper copied to clipboard

Introduce converter for `MaterialColor` class in Flutter adapter

Open DetachHead opened this issue 3 years ago • 2 comments

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

DetachHead avatar Apr 18 '22 07:04 DetachHead

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?

k-paxian avatar Apr 18 '22 20:04 k-paxian

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)

DetachHead avatar Apr 19 '22 12:04 DetachHead