Skip to content

fix(dartgen): convert mapped list fields to lists in toJson#5630

Open
fondoger wants to merge 1 commit into
zeromicro:masterfrom
fondoger:fix-dartgen-list-tojson
Open

fix(dartgen): convert mapped list fields to lists in toJson#5630
fondoger wants to merge 1 commit into
zeromicro:masterfrom
fondoger:fix-dartgen-list-tojson

Conversation

@fondoger

@fondoger fondoger commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What this PR does

This fixes Dart code generated by goctl api dartgen for class list fields in toJson().

Previously, generated toJson() returned a MappedListIterable for fields such as List<Foo> / List<Foo?>:

'items': items.map((i) => i?.toJson())

That value cannot be encoded by dart:convert when calling jsonEncode(obj.toJson()).

This PR appends .toList() in both the current and legacy dart data templates:

'items': items.map((i) => i?.toJson()).toList()

Fixes #5629.

Tests

cd tools/goctl
go test ./api/dartgen
go test ./api/...

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

1 participant