Skip to content

Fix issue with generated code when using json_serializer#453

Merged
Carapacik merged 2 commits into
Carapacik:mainfrom
frazercomputing:fix-merge-files-freezed
Apr 21, 2026
Merged

Fix issue with generated code when using json_serializer#453
Carapacik merged 2 commits into
Carapacik:mainfrom
frazercomputing:fix-merge-files-freezed

Conversation

@frazeradam
Copy link
Copy Markdown
Contributor

The Bug

When using merge_outputs: true with json_serializer: json_serializable, the generated file incorrectly includes:

part 'ffs_api.freezed.dart';
part 'ffs_api.g.dart';

It should only include:

part 'ffs_api.g.dart';

Why it's wrong

json_serializable only needs .g.dart files (for @JsonSerializable classes)
freezed needs both .freezed.dart and .g.dart files (for @Freezed classes)
The code generator correctly uses @JsonSerializable annotations (not @Freezed), but the part directive for freezed is still being added for both serializers.

Cause

The merged file template unconditionally adds part 'filename.freezed.dart' regardless of which json_serializer is configured. It should only add that line when the configuration is json_serializer: freezed.

Evidence:

With merge_outputs: false, each file correctly only has part 'filename.g.dart'
With merge_outputs: true, the freezed part directive appears even with json_serializer: json_serializable

Tests

A test has been added to make sure the changes work as desired, and other tests continue to pass.


This PR was primarily done by @TDLehman, I just did the review and got the description cleaned up and entered.

@frazeradam
Copy link
Copy Markdown
Contributor Author

This is a pretty simple fix, so I didn't bother creating a separate issue for it to resolve, but if you'd like us to do so, we can.

@frazeradam
Copy link
Copy Markdown
Contributor Author

@Carapacik anything you need from us to get this PR reviewed?

Copy link
Copy Markdown
Owner

@Carapacik Carapacik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Carapacik Carapacik merged commit e4346e2 into Carapacik:main Apr 21, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants