Skip to content

Generate unions as private-ctor + per-variant accessors + visitor (Java-8 safe) #53

Description

@OmarAlJarrah

Problem

Kotlin sealed/permits doesn't fit Java-8 generated output, and unions need forward-compat.

Proposed change

Emit unions as a private-constructor class with one nullable field per variant, an accept(Visitor<T>) that dispatches on the first non-null arm else visitor.unknown(raw) (default unknown throws), and a retained raw node on every parsed variant. Emit the deserializer against the Serde SPI, not Jackson.

Prior art: openai-java's union types (e.g. ChatCompletionContentPart.kt) — Apache-2.0.

Acceptance

  • Union codegen template + visitor
  • Unknown variant preserved, not lost
  • Test

Dependencies


Priority: high · Effort: medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenfuture KotlinPoet codegenenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions