From 544ed4b683bc2b50d2d811de76be417584abbfd9 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 20 Jul 2026 16:38:44 -0400 Subject: [PATCH] fix(dart): preserve null for optional list properties (#2656) Dart's fromJson/toJson for nullable List properties collapsed null into an empty array ("x == null ? [] : ..."), even though the field is declared nullable (List?). This lost the null-vs-empty-list distinction that some APIs rely on. mapList now emits "x == null ? null : ..." for both directions, matching the pattern already used by mapClass for nullable class-typed properties. Also re-enables the Dart optional-const-ref.schema fixture, which was previously skipped specifically because of this bug (absent optional list properties didn't round-trip). Fixes #2656 Co-Authored-By: gpt-5.6-sol via pi --- packages/quicktype-core/src/language/Dart/DartRenderer.ts | 2 +- test/languages.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/quicktype-core/src/language/Dart/DartRenderer.ts b/packages/quicktype-core/src/language/Dart/DartRenderer.ts index 8a46bd7577..52826b851f 100644 --- a/packages/quicktype-core/src/language/Dart/DartRenderer.ts +++ b/packages/quicktype-core/src/language/Dart/DartRenderer.ts @@ -322,7 +322,7 @@ export class DartRenderer extends ConvenienceRenderer { if (isNullable && !this._options.requiredProperties) { return [ list, - " == null ? [] : ", + " == null ? null : ", "List<", itemType, ">.from(", diff --git a/test/languages.ts b/test/languages.ts index 6bcfd43611..94096fd824 100644 --- a/test/languages.ts +++ b/test/languages.ts @@ -1621,9 +1621,6 @@ export const DartLanguage: Language = { "keyword-unions.schema", "ref-remote.schema", "uuid.schema", - /* Absent optional lists don't round-trip: the generated fromJson/toJson - turn them into [], so the output no longer matches the input */ - "optional-const-ref.schema", ], skipMiscJSON: true, rendererOptions: {},