From aadc24d47d81c4d672c65257d13f30f598a9064b Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 6 Jul 2026 16:18:23 -0400 Subject: [PATCH 1/2] Dart: null-guard nullable date fields in toJson For a nullable "date" transformed-string field, the Dart renderer's toJson emitted a template string over `x!.year` / `x!.month` / `x!.day` with no null check, so serializing an instance whose date field is null threw "Null check operator used on a null value" at runtime. Nullable date-time fields were already handled correctly with `?.toIso8601String()`. Emit `x == null ? null : "${x!...}"` in the null-safe nullable branch, mirroring the null guards used in fromJson. Adds test/inputs/json/priority/bug2590.json, a fixture input with a nullable yyyy-mm-dd date field, so the dart fixture round-trips it in CI. Fixes #2590 Co-Authored-By: Claude Fable 5 --- .../src/language/Dart/DartRenderer.ts | 3 ++- test/inputs/json/priority/bug2590.json | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/inputs/json/priority/bug2590.json diff --git a/packages/quicktype-core/src/language/Dart/DartRenderer.ts b/packages/quicktype-core/src/language/Dart/DartRenderer.ts index f5220d2505..3c24da88df 100644 --- a/packages/quicktype-core/src/language/Dart/DartRenderer.ts +++ b/packages/quicktype-core/src/language/Dart/DartRenderer.ts @@ -603,7 +603,8 @@ export class DartRenderer extends ConvenienceRenderer { (transformedStringType.isNullable || isNullable) ) { return [ - '"${', + dynamic, + ' == null ? null : "${', dynamic, "!.year.toString().padLeft(4, '0')", "}-${", diff --git a/test/inputs/json/priority/bug2590.json b/test/inputs/json/priority/bug2590.json new file mode 100644 index 0000000000..60e067955a --- /dev/null +++ b/test/inputs/json/priority/bug2590.json @@ -0,0 +1,14 @@ +{ + "invoices": [ + { + "name": "invoice-1", + "dueDate": "2023-01-15", + "createdAt": "2023-01-15T10:30:00Z" + }, + { + "name": "invoice-2", + "dueDate": null, + "createdAt": null + } + ] +} From 37d0f9066190833b53dbeeaeb4bcb9e3dc671181 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 6 Jul 2026 16:47:49 -0400 Subject: [PATCH 2/2] Skip nullable date-time fixture for TypeScript-Zod --- test/languages.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/languages.ts b/test/languages.ts index a31f78b6f5..c9cdccdab2 100644 --- a/test/languages.ts +++ b/test/languages.ts @@ -1563,6 +1563,9 @@ export const TypeScriptZodLanguage: Language = { // Does not handle top level array "bug863.json", + // z.coerce.date() coerces null to the Unix epoch: #2880 + "bug2590.json", + "no-classes.json", "00c36.json", "10be4.json",