rrousselGit / freezed

Code generation for immutable classes that has a simple syntax/API without compromising on the features.
https://pub.dev/packages/freezed
1.94k stars 237 forks source link

Is there a way of defining multiple converters in Freezed constructor. #1127

Open haodong404 opened 2 months ago

haodong404 commented 2 months ago

Like JsonSerializable, we can define many converters using the argument converters.

@JsonSerializable(converters: [DateTimeConverter(), IntConverter()])

But Freezed does not have the same argument. So, I'm wondering if there's a convenient way to set up a lot of converters.

haodong404 commented 2 months ago

I noticed that define a @JsonSerializable above the factory constructor in a Freezed class can solve this problem.

class Test with _$Test {
  @JsonSerializable(converters: [DateTimeConverter(), IntConverter()])
  const factory Test( {
    int? id,
  });
}