@@ -189,11 +189,8 @@ String _generateFieldDeserializers(
189189 final typeDefNode =
190190 getTypeDefinitionNode (schemaSource.document, originalSymbolName);
191191
192- //TODO this feels flaky, find a better way
193- final isBuilder = type.url != null &&
194- ! isWrappedValue &&
195- (typeDefNode is ! ScalarTypeDefinitionNode &&
196- typeDefNode is ! EnumTypeDefinitionNode );
192+ // Check if this is a built type that needs .replace() method
193+ final isBuilder = ! isWrappedValue && _isBuiltType (type, typeDefNode);
197194
198195 const fieldNameVariableName = "_\$ fieldValue" ;
199196
@@ -297,3 +294,26 @@ bool _isValue(Reference ref) {
297294
298295 return ref.symbol == valueTypeRef.symbol && ref.url == valueTypeRef.url;
299296}
297+
298+ bool _isBuiltType (TypeReference type, TypeDefinitionNode ? typeDefNode) {
299+ // Built collection types (BuiltList, BuiltMap, etc.)
300+ final bool isFromBuiltCollectionPackage =
301+ type.url? .contains ("built_collection" ) ?? false ;
302+ if (isFromBuiltCollectionPackage) {
303+ return true ;
304+ }
305+
306+ // Built value types (generated classes that implement Built)
307+ if (typeDefNode != null &&
308+ (typeDefNode is InputObjectTypeDefinitionNode ||
309+ typeDefNode is ScalarTypeDefinitionNode )) {
310+ return true ;
311+ }
312+
313+ // Types with Builder suffix pattern
314+ if (type.symbol.endsWith ("Builder" )) {
315+ return true ;
316+ }
317+
318+ return false ;
319+ }
0 commit comments