Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WARNING] retrofit_generator on retrofit @RestApi() must provide a toJson() method which return a Map #577

Closed
okdevy opened this issue May 24, 2023 · 7 comments

Comments

@okdevy
Copy link

okdevy commented May 24, 2023

Having these [WARNING]s when generating retrofit services:



Code snippet:

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:models/enums/user_type.dart';

part 'login_body.freezed.dart';
part 'login_body.g.dart';

@Freezed()
class LoginBody with _$LoginBody {
  factory LoginBody({
    required String email,
    required String password,
    @JsonKey(name: 'user_type') required UserTypeEnum userType,
  }) = _LoginBody;

  factory LoginBody.fromJson(Map<String, dynamic> json) =>
      _$LoginBodyFromJson(json);
}
dart run build_runner build --delete-conflicting-outputs

Building package executable... (3.9s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 148ms
[INFO] Precompiling build script... completed, took 4.4s
[INFO] Building new asset graph completed, took 400ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 3ms
[INFO] Generating SDK summary completed, took 2.7s
[WARNING] retrofit_generator on lib/api/auth.dart:
LoginBody must provide a `toJson()` method which return a Map.
It is programmer's responsibility to make sure the LoginBody is properly serialized
[WARNING] retrofit_generator on lib/api/auth.dart:
……..

[INFO] Running build completed, took 4.6s
[INFO] Caching finalized dependency graph completed, took 41ms
[INFO] Succeeded after 4.7s with 55 outputs (162 actions)



environment:
  sdk: '>=2.19.2 <3.0.2'

dependencies:
  dio: ^5.1.2
  fast_immutable_collections: ^9.1.1
  freezed_annotation: ^2.2.0
  json_annotation: ^4.8.1
  logging: ^1.2.0
  models:
    path: ../models
  retrofit: ^4.0.1

dev_dependencies:
  build_runner: '>=2.3.0 <4.0.0'

  freezed: ^2.3.4
  json_serializable: ^6.7.0
  lint:
    git:
      url: "https://github.com/pro100andrey/lint.git"
  retrofit_generator: ^7.0.1

dependency_overrides:
  analyzer: ^5.5.0 



~ flutter doctor -v
 
[✓] Flutter (Channel stable, 3.10.1, on macOS 13.4 22F66 darwin-arm64, locale en-UA)
   • Flutter version 3.10.1 on channel stable at /Users/oleksandrkrinickyi/flutter
   • Upstream repository https://github.com/flutter/flutter.git
   • Framework revision d3d8effc68 (8 days ago), 2023-05-16 17:59:05 -0700
   • Engine revision b4fb11214d
   • Dart version 3.0.1
   • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
   • Android SDK at /Users/oleksandrkrinickyi/Library/Android/sdk
   • Platform android-33, build-tools 34.0.0-rc1
   • ANDROID_HOME = /Users/oleksandrkrinickyi/Library/Android/sdk
   • Java binary at: /Applications/Android
     Studio.app/Contents/jbr/Contents/Home/bin/java
   • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
   • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
   • Xcode at /Applications/Xcode.app/Contents/Developer
   • Build 14E222b
   • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
   • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
   • Android Studio at /Applications/Android Studio.app/Contents
   • Flutter plugin can be installed from:
     🔨 https://plugins.jetbrains.com/plugin/9212-flutter
   • Dart plugin can be installed from:
     🔨 https://plugins.jetbrains.com/plugin/6351-dart
   • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.78.2)
   • VS Code at /Applications/Visual Studio Code.app/Contents
   • Flutter extension version 3.64.0

[✓] Connected device (3 available)
   • iPhone 14 Pro Max (mobile) • C6D7D553-C66C-4058-A0F7-E3ECFFCBEE3D • ios
     • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
   • macOS (desktop)            • macos                                • darwin-arm64
     • macOS 13.4 22F66 darwin-arm64
   • Chrome (web)               • chrome                               • web-javascript
     • Google Chrome 113.0.5672.126

[✓] Network resources
   • All expected network resources are available.

• No issues found!
@okdevy okdevy changed the title [WARNING] retrofit_generator on lib/api/auth.dart: [WARNING] retrofit_generator on ... May 24, 2023
@okdevy okdevy changed the title [WARNING] retrofit_generator on ... [WARNING] retrofit_generator on retrofit @RestApi() May 24, 2023
@okdevy okdevy changed the title [WARNING] retrofit_generator on retrofit @RestApi() [WARNING] retrofit_generator on retrofit @RestApi() must provide a toJson() method which return a Map May 24, 2023
@donpaul120
Copy link

donpaul120 commented May 25, 2023

I'm also having this issue, please, were you able to make this work @venomanse

@HelenaSewell
Copy link

Are you using Dart 3? The problem might be this: rrousselGit/freezed#916

@okdevy
Copy link
Author

okdevy commented May 31, 2023

Are you using Dart 3? The problem might be this: rrousselGit/freezed#916

yes, that issue came when I migrated to dart 3.

Thank you for response.

@okdevy
Copy link
Author

okdevy commented May 31, 2023

Are you using Dart 3? The problem might be this: rrousselGit/freezed#916

refer to reply from @HelenaSewell

@okdevy okdevy closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
@PITPL-Yogita-Agarwal
Copy link

this issue has not been resolved @venomanse, it is still not quite clear to me how to solve this,is this issue solved..

@mrruby
Copy link

mrruby commented Jul 19, 2023

Still not resolved

@lucasdidur
Copy link

This happens when using @Body annotation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants