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

Issue with JsonSerializable and contructor with none or one argument #91

Open
fatshady opened this issue Jun 8, 2023 · 0 comments
Open

Comments

@fatshady
Copy link

fatshady commented Jun 8, 2023

Hi,
Given an example dto like the following, with serializable's toJson / fromJson methods

@JsonSerializable(explicitToJson: true)
class ActivityAssetsDto {
  @JsonKey(name: 'image')
  final String imageUrl;

  const ActivityAssetsDto({this.imageUrl = ""});

  factory ActivityAssetsDto.fromJson(Map<String, dynamic> json) =>
      _$ActivityAssetsDtoFromJson(json);

  Map<String, dynamic> toJson() => _$ActivityAssetsDtoToJson(this);
}

it generates

@override
  ActivityAssetsDto fromActivityAssets(ActivityAssets entity) {
    final activityassetsdto = ActivityAssetsDto.fromJson();
    return activityassetsdto;
  }

using "fromJson()" as constructor (obviously without parameter since it doesn't know what tu put there)

if I add a second parameter to the ActivityAssetsDto constructor the generator picks the correct constructors without problems.
It seems that the strategy of getting the constructor with the most arguments does not always work.

thank you for your time

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

1 participant