Skip to content

dartgen: materialize mapped class lists in toJson to avoid jsonEncode failures#5636

Draft
kevwan with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-dartgen-tojson-list-fields
Draft

dartgen: materialize mapped class lists in toJson to avoid jsonEncode failures#5636
kevwan with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-dartgen-tojson-list-fields

Conversation

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

goctl api dartgen was emitting toJson() for class-list fields with map(...) only, producing MappedListIterable values that fail jsonEncode. This change updates generation so list fields serialize as concrete JSON arrays.

  • Generator fix (legacy + v2 templates)

    • Updated Dart toJson() generation for isClassListType members to append .toList().
    • Ensures generated payloads are List-backed and encodable by dart:convert.
  • Regression coverage

    • Added/updated focused dartgen test assertions to verify generated toJson() for class-list fields includes .toList() and does not regress.

Example of generated output after this change:

Map<String, dynamic> toJson() {
  return {
    'items': items.map((i) => i?.toJson()).toList(),
  };
}

Copilot AI changed the title [WIP] Fix issue in dartgen for list fields in toJson dartgen: materialize mapped class lists in toJson to avoid jsonEncode failures Jun 9, 2026
Copilot finished work on behalf of kevwan June 9, 2026 01:50
Copilot AI requested a review from kevwan June 9, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug in dartgen] list fields in toJson miss .toList(), causing jsonEncode failure

2 participants