Skip to content

Class needs default constructor even when generating only toJson() #1038

@leoshusar

Description

@leoshusar

My class looks like this

@JsonSerializable(createFactory: false)
class ArticleId {
  final String? id;
  final String? ean;

  ArticleId.id(this.id)
    : ean = null;

  ArticleId.ean(this.ean)
    : id = null;

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

and even though I am generating only toJson, it shows The class `ArticleId` has no default constructor.

I don't know if this is intended or not, but currently I have to create private constructor with // ignore: unused_element to satisfy the analyzer, which would be nice to not have to do.

I'm on latest json_serializable 6.0.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions