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

Error when using mobx adapter #67

Closed ksmsk closed 4 years ago

ksmsk commented 4 years ago

dependencies:

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  mobx: ^1.2.1
  dart_json_mapper: ^1.5.14
  dart_json_mapper_mobx: ^1.2.1
  ...
dev_dependencies:
  build_runner: ^1.0.0
  mobx_codegen: ^1.1.0
  ...

There is this error type '() => (_SyncIterator<PropertyAccessorElement>) => bool' is not a subtype of type '() => (_SyncIterator<ExecutableElement>) => bool' when using mobx_codegen and dart_json_mapper together. Eventhough it says build failed, it still manages to generate successfully.

here's the code:

void main() {
  initializeReflectable();
  JsonMapper().useAdapter(mobXAdapter);
  runApp(App());
}

///////////////////////////////////////////////////

part 'login_request_dto.g.dart';

@jsonSerializable
class LoginRequestDTO extends _LoginRequestDTO with _$LoginRequestDTO {
  static LoginRequestDTO fromJson(dynamic json) => JsonMapper.deserialize(json);
}

abstract class _LoginRequestDTO extends BaseModel with Store {
  @observable
  String app = "mobile";
  @observable
  String lang = "en";
  @observable
  String password = "";
  @observable
  String username = "";
}

BaseModel contains helper methods nothing else. I tried with constructors aswell still same error.

k-paxian commented 4 years ago

Not sure this error somehow related to mapper, could you please provide more consistent information. At least error stack trace should contain mapper source code or mobx adapter code

ksmsk commented 4 years ago

Hey @k-paxian, i made a repository to reproduce the problem. https://github.com/ksmsk/json_mapper_bug_reprod

btw im using flutter beta channel. I forgot to mention that.

Flutter 1.19.0-4.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision f994b76974 (7 days ago) • 2020-06-09 15:53:13 -0700
Engine • revision 9a28c3bcf4
Tools • Dart 2.9.0 (build 2.9.0-14.1.beta)
ksmsk commented 4 years ago

update: I dig into problem and found out the problem related to flutter beta channel's analyzer. related issue: https://github.com/dart-lang/reflectable/issues/210. reverting flutter channel to stable fixed the issue.

slightly off-topic: when will you update dart_json_mapper to build_runner_core 6? Latest build_runner no longer compatible with dart_json_mapper.

k-paxian commented 4 years ago

yep, reflectable library is sensible to analyzer version. Well dart_json_mapper depends heavily on reflectable library, so once it will be updated to the latest build_runner according to this issue https://github.com/dart-lang/reflectable/issues/209 then dart_json_mapper will be aligned too.

Thank you for investigation efforts :)