Fix: JsonObject fields should not use replace() method with tristate_optionals #497
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.
Description
This PR fixes an issue where
JsonObject
fields incorrectly generate calls to.replace()
method whentristate_optionals
is enabled.Problem
When using Ferry with
JsonObject
type (frombuilt_value
package) andtristate_optionals: true
option enabled, the generated serializer code contains calls to.replace()
method onJsonObject?
fields. However,JsonObject
doesn't have areplace
method, causing compilation errors.Solution
Added special handling for
JsonObject
type in the tristate optionals code generator to ensure it's treated as a simple value type (using direct assignment) rather than a built collection type (which would use.replace()
method).Changes
/codegen/gql_code_builder/lib/src/tristate_optionals.dart
to detectJsonObject
type and exclude it from being treated as a builder typeTesting
Tested with a real-world Flutter project using:
tristate_optionals: true
JsonObject
type override for JSON scalarRelated Issues
Before/After
Before (causes compilation error):
After (works correctly):