k-paxian / dart-json-mapper

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

Can't convert List 'List<dynamic>' is not a subtype of type 'List<AppOtherLink>' #189

Closed au-top closed 2 years ago

au-top commented 2 years ago

Hello, I have the same problem

I have two projects. In one of them, he will automatically set

inal mainGeneratedAdapter = JsonMapperAdapter(
  title: 'free_store',
  url: 'package:free_store/main.dart',
  reflectableData: _data,
  memberSymbolMap: _memberSymbolMap,
  valueDecorators: {
    typeOf<List<x0.BasePackage>>(): (value) => value.cast<x0.BasePackage>(),
    typeOf<Set<x0.BasePackage>>(): (value) => value.cast<x0.BasePackage>(),
    typeOf<List<x0.SignUpPackage>>(): (value) => value.cast<x0.SignUpPackage>(),
    typeOf<Set<x0.SignUpPackage>>(): (value) => value.cast<x0.SignUpPackage>(),
    typeOf<List<x0.SignInPackage>>(): (value) => value.cast<x0.SignInPackage>(),
    typeOf<Set<x0.SignInPackage>>(): (value) => value.cast<x0.SignInPackage>(),
    typeOf<List<x0.AppIndexInfo>>(): (value) => value.cast<x0.AppIndexInfo>(),
    typeOf<Set<x0.AppIndexInfo>>(): (value) => value.cast<x0.AppIndexInfo>(),
    typeOf<List<x0.RegisterAppPackage>>(): (value) => value.cast<x0.RegisterAppPackage>(),
    typeOf<Set<x0.RegisterAppPackage>>(): (value) => value.cast<x0.RegisterAppPackage>(),
    typeOf<List<x0.AppOtherLink>>(): (value) => value.cast<x0.AppOtherLink>(),
    typeOf<Set<x0.AppOtherLink>>(): (value) => value.cast<x0.AppOtherLink>(),
    typeOf<List<x0.AppVersionLog>>(): (value) => value.cast<x0.AppVersionLog>(),
    typeOf<Set<x0.AppVersionLog>>(): (value) => value.cast<x0.AppVersionLog>()
},
  enumValues: {

});

But I moved some of the same things to another project


final mainGeneratedAdapter = JsonMapperAdapter(
  title: 'free_message',
  url: 'package:free_message/main.dart',
  reflectableData: _data,
  memberSymbolMap: _memberSymbolMap,
  valueDecorators: {

},
  enumValues: {

});

Why Bmain.mapper.g.dart.txt Amain.mapper.g.dart.txt ?

k-paxian commented 2 years ago

As far as I understood the need, you've managed to separate some code into shared library project and you are using this library in other apps? If so here are the similar issues #182 & #162 resolved.

To be short, you need to specify auto generated adapter from shared library in the mapper initialization code from the target app

// Import auto generated adapter from shared package
import 'package:starlink/starlink.dart' show starlinkGeneratedAdapter;
import 'package:unit_testing/unit_testing.dart' show unitTestingGeneratedAdapter;

// Main App bootstrap, you need to specify those adapters when initializing mapper
void main() {
  initializeJsonMapper(
      adapters: [starlinkGeneratedAdapter, unitTestingGeneratedAdapter]);
}