Skip to content

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

Description

@fatshady

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions