Jaguar-dart / jaguar_serializer

Format (JSON, XML, protobuf, mongodb, etc) and platform (server, client) agnostic serialization framework
172 stars 34 forks source link

Code not generated in Flutter #177

Closed josephmangmang closed 5 years ago

josephmangmang commented 5 years ago

Always failed. I'm using the latest version.

NoSuchMethodError: The getter 'displayName' was called on null.

[INFO] Generating build script... [INFO] Generating build script completed, took 682ms

[INFO] Initializing inputs [INFO] Reading cached asset graph... [INFO] Reading cached asset graph completed, took 194ms

[INFO] Checking for updates since last build... [INFO] Checking for updates since last build completed, took 1.7s

[INFO] Running build... [INFO] Running build completed, took 33ms

[INFO] Caching finalized dependency graph... [INFO] Caching finalized dependency graph completed, took 95ms

[SEVERE] jaguar_serializer_cli:jaguar_serializer_cli on lib/src/models/hashtag.dart (cached): Error running JaguarSerializerGenerator NoSuchMethodError: The getter 'displayName' was called on null. Receiver: null Tried calling: displayName [SEVERE] Failed after 154ms pub failed (1)

matthewrice345 commented 5 years ago

+1

matthewrice345 commented 5 years ago

If I comment out my test dependencies I can successfully run the CLI flutter_test: sdk: flutter test:

escamoteur commented 5 years ago

Same here, I'm blocked because of that

sdebruyn commented 5 years ago

Same here...

Verbose output:

Error running JaguarSerializerGenerator
NoSuchMethodError: The getter 'displayName' was called on null.
Receiver: null
Tried calling: displayName
dart:core                                                               Object.noSuchMethod
package:jaguar_serializer_cli/src/writer/writer.dart 129:43             Writer._writeCtor.<fn>
dart:core                                                               List.forEach
package:jaguar_serializer_cli/src/writer/writer.dart 126:24             Writer._writeCtor
package:jaguar_serializer_cli/src/writer/writer.dart 107:5              Writer._fromWriter
package:jaguar_serializer_cli/src/writer/writer.dart 31:5               Writer.generate
package:jaguar_serializer_cli/src/generator.dart 41:14                  JaguarSerializerGenerator.generateForAnnotatedElement
package:source_gen/src/generator_for_annotation.dart 47:28              GeneratorForAnnotation.generate
package:source_gen/src/builder.dart 254:35                              _generate
package:source_gen/src/builder.dart 72:15                               _Builder._generateForLibrary
package:source_gen/src/builder.dart 66:11                               _Builder.build
package:build                                                           runBuilder
package:build_runner_core/src/generate/build_impl.dart 460:19           _SingleBuild._runForInput.<fn>.<fn>.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 303:15  _NoOpBuilderActionTracker.trackStage
package:build_runner_core/src/generate/build_impl.dart 458:23           _SingleBuild._runForInput.<fn>.<fn>
package:timing/src/timing.dart 222:44                                   NoOpTimeTracker.track
package:build_runner_core/src/generate/build_impl.dart 417:22           _SingleBuild._runForInput.<fn>
package:pool/pool.dart 127:28                                           Pool.withResource
package:build_runner_core/src/generate/build_impl.dart 413:17           _SingleBuild._runForInput
package:build_runner_core/src/generate/build_impl.dart 363:38           _SingleBuild._runBuilder.<fn>
dart:async                                                              Future.wait
package:build_runner_core/src/generate/build_impl.dart 362:36           _SingleBuild._runBuilder
dart:async                                                              _AsyncAwaitCompleter.start
package:build_runner_core/src/generate/build_impl.dart 360:40           _SingleBuild._runBuilder
package:build_runner_core/src/generate/build_impl.dart 309:20           _SingleBuild._runPhases.<fn>.<fn>
dart:async                                                              _completeOnAsyncReturn
package:build_runner_core/src/generate/build_impl.dart                  _SingleBuild._matchingPrimaryInputs
sdebruyn commented 5 years ago

Looks like this issue has nothing to do with Flutter. There's just a coding error on this line which was introduced in 2.1.1. You can't use previous versions because they're not compatible with Dart 2.

It's checking if param is null and if so it's using a getter on param which is not possible :)

A workaround can be referencing jaguar_serializer_cli from a local path in your pubspec, cloning this repo and replacing that line with _w.write('null');

I'm not experienced enough with build_runner stuff to do a PR myself to properly fix this.

tejainece commented 5 years ago

@SamuelDebruyn Thats for insight into the issue.

I will fix this.

tejainece commented 5 years ago

Fixed in commit https://github.com/Jaguar-dart/jaguar_serializer/commit/ea3d986d9025be95c71006583c9903bece3a53f2.

Released as version jaguar_serializer_cli 2.2.8. Please test it and let me if the issue is fixed.

sdebruyn commented 5 years ago

@tejainece That fixed it, thanks!