Skip to content

Improve union-types serialization#6

Merged
adbenitez merged 1 commit into
mainfrom
copilot/fix-mute-duration-serialization
Mar 6, 2026
Merged

Improve union-types serialization#6
adbenitez merged 1 commit into
mainfrom
copilot/fix-mute-duration-serialization

Conversation

Copilot AI commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Variant structs like MuteDurationNotMuted included Kind string as a regular Go field. Since the zero value of string is "", &MuteDurationNotMuted{} would marshal as {"kind":""} instead of {"kind":"NotMuted"}, requiring users to manually set the Kind field to the proper value.

Changes

  • generate_variant_struct: Excludes the kind field from struct properties (it's a discriminator, not user data) and adds a MarshalJSON method per variant that always injects the correct kind value using the alias pattern to avoid infinite recursion.
  • TypeGenerator: Adds has_union_types() method.
  • types.go.j2: Extends the encoding/json import condition to trigger when union types exist (since the new MarshalJSON uses json.Marshal).

Copilot AI changed the title [WIP] Fix serialization of MuteDuration variants for RPC Fix discriminated union variant structs always serializing kind as empty string Mar 4, 2026
@adbenitez adbenitez force-pushed the copilot/fix-mute-duration-serialization branch from 25efbc6 to 257e56a Compare March 6, 2026 00:29
@adbenitez adbenitez changed the title Fix discriminated union variant structs always serializing kind as empty string Improve union-types serialization Mar 6, 2026
@adbenitez adbenitez marked this pull request as ready for review March 6, 2026 00:32
@adbenitez adbenitez merged commit 00ed80f into main Mar 6, 2026
3 checks passed
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.

2 participants