schultek / dart_mappable

Improved json serialization and data classes with full support for generics, inheritance, customization and more.
https://pub.dev/packages/dart_mappable
MIT License
135 stars 20 forks source link

fromMap causes Exception when used with generic type #178

Closed MohaAmiry closed 3 months ago

MohaAmiry commented 3 months ago

the following code throws an exception:

import 'package:dart_mappable/dart_mappable.dart';

part 'Test.mapper.dart';

@MappableClass()
class Response<T> with ResponseMappable<T> {
  const Response();
  static const fromMap = ResponseMapper.fromMap;
}

@MappableClass()
class Model with ModelMappable {
  const Model();
}

// exception: MapperException: Failed to decode (Response<Model>): type 'Response<UnresolvedType>' is not a subtype of type 'Response<Model>' in type cast
Response<Model> modelResponse = Response.fromMap({});

how to cast Response<Model> from a map using dart_mappable?

schultek commented 3 months ago

Try calling ModelMapper.ensureInitialized() beforehand.

MohaAmiry commented 3 months ago

problem solved, thank you :).. i really appreciate the quick response, most of package maintainers take very long time to respond to issues.