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

Can't deserialize a map with two custom generic types #66

Closed AlaaEldeenYsr closed 4 years ago

AlaaEldeenYsr commented 4 years ago

The issue is coming from here final Map<ThemeMode, StylingModel> styling;

@jsonSerializable
class Config {
  Config({this.styling});
  static Map<Type, ValueDecoratorFunction> valueDecorators() {
    return {
      typeOf<Map<ThemeMode, StylingModel>>(): (value) => value.cast<ThemeMode, StylingModel>(),
    };
  }
  @JsonProperty(enumValues: ThemeMode.values)
  final Map<ThemeMode, StylingModel> styling;
}

Here is the StylingModel

@jsonSerializable
class StylingModel {
  const StylingModel({this.primary});
  final String primary;
}

And the ThemeMode is a built in enum in flutter. Actually the issue is not that i'm using a non-annotated enum because as you see in the following example the FontWeight is built in flutter and it's working well.

@jsonSerializable
class TypographyType {
  const TypographyType({@required this.fontWeight,});
  @JsonProperty(enumValues: FontWeight.values)
  final FontWeight fontWeight;
}

So i guess that the issue is coming from using two custom generic types in the Map<CustomEnum, CustomClass>, So please help mater @k-paxian

k-paxian commented 4 years ago

Thanks, fixed as of 1.5.15 here is the unit test reference https://github.com/k-paxian/dart-json-mapper/blob/4ffdd6913a15d6429d77e3fec3bf411bf025f0c8/mapper/test/test.enums.dart#L133