Search code examples
flutterdartfreezed

Stop Freezed from generating toJson


According to the Freezed documentation:

enter image description here

However, I'm using => in my code as follows:

 factory ProductLineDTO.fromJson(Map<String, dynamic> json) =>
      _$ProductLineDTOFromJson(json['node']);

Yet I get the toJson which I don't need. Any idea how to stop Freezed from generating toJson function?


Solution

  • Might be late, but according to the issues and the documentation, the right way to stop generating either toJson or fromJson is to use @Freezed() instead of @freezed

    For example

    @Freezed(toJson: false, fromJson: true)
    

    See the @Freezed source file

    Or even the issue where the author of freezed, Remi Rousselet, mentions it