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

version 2.2.5 error: List<dynamic> is not type List<String> #192

Closed au-top closed 1 year ago

au-top commented 1 year ago

Version 2.2.5 cannot encode/decode normally

But 2.2.4+2 can

I haven't tested 2.2.5+1 because my dependency doesn't support 2.2.5+1

Is this a bug?

he error info

List<dynamic> is not type List<String>

code

@jsonSerializable
class AppVersionLog {
  String package;

  String appIcon;
  String version;
  String appName;
  String describe;
  String mainImage;
  List<String> images;

  String? android;
  String? windows;
  String? ios;
  String? linux;
  String? macos;

  int? createDate;

  AppVersionLog(
    this.appIcon,
    this.package,
    this.version,
    this.appName,
    this.describe,
    this.mainImage,
    this.images,
    this.createDate,
    this.android,
    this.ios,
    this.windows,
    this.macos,
    this.linux,
  );

  AppVersionLog.fromName({
    required this.appIcon,
    required this.package,
    required this.version,
    required this.appName,
    required this.describe,
    required this.mainImage,
    required this.images,
    this.createDate,
    this.android,
    this.ios,
    this.windows,
    this.macos,
    this.linux,
  });
}

If someone encounters the same problem as me, you can try to lock the version lock version to 2.2.4+2

   dependency_overrides:
       dart_json_mapper: 2.2.4+2

or

dependencies: 
    dart_json_mapper: 2.2.4+2
k-paxian commented 1 year ago

Can I ask you to provide the usage code, where the error occurs specifically?

au-top commented 1 year ago

@k-paxian Sorry, I found out that the dart_json_mapper in my shared code base is inconsistent with the current project version. But so far I have a question about the multi-project setup, how do I go about the same version when sharing the code base with multiple projects For example I have three projects project: a b c

they depend on a version constraint dart_json_mapper: ^2.2.2

I can't guarantee that the versions in their actual .lock files are in sync And because I need to execute dart pub run build_runner build for each project, it will cause some problems, how can I ensure that the versions in the three projects are consistent, or can I support one

export 'package:free_store_share/protocol/protocol_package.dart';
export 'config_def.dart';
export './json_mapper_export.mapper.g.dart' show jsonMapperExportGeneratedAdapter, initializeJsonMapper, initializeJsonMapperAsync;

void main() {}

I can import a class with @jsonSerializable from another project and then call dart pub run build_runner build in one project to generate a xxx.mapper.g.dart file unique to this project instead of via xxxxGeneratedAdapter Adapter because Adapter means I need to execute dart pub run build_runner build separately for each project that has dart_json_mapper

k-paxian commented 1 year ago

Well it depends on your assumptions about that shared code, and how many peers are working on that shared projects? how often those shared projects has changes? etc.

You have all the options, from the monolith usage inside the destination app project, then you'll need to maintain only one generated file. Or you could go on full isolation to separate the code across the a,b,c,... shared projects. Depends on your project setup, and expected code life cycle - what suits your project purpose better. There is no silver bullet for that.

As well you could automate the dart pub run build_runner build step using CI/CD tools, etc.