Skip to content

Freezed with JsonSerializable #1321

@Elevencode

Description

@Elevencode

Describe the bug
When upgrading freezed from version 2.5.7 to 3.2.3, there was a problem with generating .freezed and .g files. The .g file was not generated at all.

The method '_$WalletUserFromJson' isn't defined for the type 'WalletUser'.
Try correcting the name to the name of an existing method, or defining a method named '_$WalletUserFromJson'.

To Reproduce

part 'wallet_user.c.g.dart';
part 'wallet_user.c.freezed.dart';

@Freezed(toJson: true)
abstract class WalletUser with _$WalletUser {
  @JsonSerializable(fieldRename: FieldRename.snake, explicitToJson: true, createToJson: true)
  const factory WalletUser({
    required int masterId,
    String? id,
  }) = _WalletUser;

  factory WalletUser.fromJson(Map<String, dynamic> json) => _$WalletUserFromJson(json);
}

Expected behavior
Everything should work as before, including fieldRename

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions