Fix issue with generated code when using json_serializer#453
Merged
Carapacik merged 2 commits intoApr 21, 2026
Conversation
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. |
Contributor
Author
|
@Carapacik anything you need from us to get this PR reviewed? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Bug
When using
merge_outputs: truewithjson_serializer: json_serializable, the generated file incorrectly includes:It should only include:
Why it's wrong
json_serializableonly needs.g.dartfiles (for@JsonSerializableclasses)freezedneeds both.freezed.dartand.g.dartfiles (for@Freezedclasses)The code generator correctly uses
@JsonSerializableannotations (not@Freezed), but thepartdirective forfreezedis still being added for both serializers.Cause
The merged file template unconditionally adds
part 'filename.freezed.dart'regardless of whichjson_serializeris configured. It should only add that line when the configuration isjson_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.