Fix: JsonObject fields should not use replace() method with tristate_optionals #497
+6
−0
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
JsonObjectfields incorrectly generate calls to.replace()method whentristate_optionalsis enabled.Problem
When using Ferry with
JsonObjecttype (frombuilt_valuepackage) andtristate_optionals: trueoption enabled, the generated serializer code contains calls to.replace()method onJsonObject?fields. However,JsonObjectdoesn't have areplacemethod, causing compilation errors.Solution
Added special handling for
JsonObjecttype 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.dartto detectJsonObjecttype and exclude it from being treated as a builder typeTesting
Tested with a real-world Flutter project using:
tristate_optionals: trueJsonObjecttype override for JSON scalarRelated Issues
Before/After
Before (causes compilation error):
After (works correctly):