From 484317f53af7811115eaf3aa280fc4a1e6c16790 Mon Sep 17 00:00:00 2001 From: Bae Junehyeon Date: Mon, 1 Sep 2025 13:42:53 +0900 Subject: [PATCH] Fix: JsonObject fields should not use replace() method with tristate_optionals When tristate_optionals is enabled, the code generator incorrectly treats JsonObject from built_value package as a built collection that has a replace() method. However, JsonObject is a simple value type without replace() method. This fix adds special handling for JsonObject to ensure it's treated as a simple value type, using direct assignment instead of replace() method. Fixes gql-dart/ferry#649 --- codegen/gql_code_builder/lib/src/tristate_optionals.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codegen/gql_code_builder/lib/src/tristate_optionals.dart b/codegen/gql_code_builder/lib/src/tristate_optionals.dart index b4e0a77f..e6a08af8 100644 --- a/codegen/gql_code_builder/lib/src/tristate_optionals.dart +++ b/codegen/gql_code_builder/lib/src/tristate_optionals.dart @@ -187,8 +187,14 @@ String _generateFieldDeserializers( getTypeDefinitionNode(schemaSource.document, originalSymbolName); //TODO this feels flaky, find a better way + // Check if type is a built collection (has replace method) + // JsonObject from built_value doesn't have replace method + final isJsonObject = type.symbol == "JsonObject" && + type.url == "package:built_value/json_object.dart"; + final isBuilder = type.url != null && !isWrappedValue && + !isJsonObject && (typeDefNode is! ScalarTypeDefinitionNode && typeDefNode is! EnumTypeDefinitionNode);