You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Klaxon and Jackson make this work with hand-written converters that inspect the raw JSON and pick the matching member. The kotlinx renderer emits only the bare @Serializable sealed class — and kotlinx-serialization's default handling for sealed classes is discriminated polymorphism, expecting {"type": ..., ...} objects. The actual JSON for a quicktype union is the bare value itself (e.g. "quux" or 3.14), so decoding throws at runtime and encoding produces the wrong shape.
feat(kotlin): Support for date and datetime from JSON schema #2845 (Kotlin date/date-time support) makes it more visible: e.g. in test/inputs/schema/date-time-or-string.schema, the property bar: oneOf [date-time, enum] used to collapse to plain String (no date-time type ⇒ string absorbed the union) but now becomes a genuine date-time | enum union, so date-time.schema and date-time-or-string.schema also have to stay skipped for kotlinx.
keyword-unions.schema is additionally blocked by a synthesized-constructor >255-parameter JVM limit.
Proposed fix
Emit a custom KSerializer<XUnion> per union that dispatches on JSON shape (JsonPrimitive/string/number/boolean/JsonObject/JsonArray, with isString etc. to disambiguate), mirroring the member-matching logic (and match priority) that the klaxon/jackson converters use, and register it via @Serializable(with = ...) on the sealed class. The @file:UseSerializers + same-file serializer pattern introduced for date/time serializers in #2845 can be extended for this.
Acceptance: lift the union-related skips in test/languages.ts for KotlinXLanguage (JSON union inputs, union.schema et al., date-time.schema, date-time-or-string.schema) and claim the union feature so the .fail.union.json samples run.
Related gaps (same TODO line, possibly separate follow-ups)
Top-level arrays: rendered as typealias TopLevel = JsonArray<T>, which does not compile (JsonArray takes no type parameters) — currently 40 JSON inputs + union.schema skipped, and 77392.json/b4865.json in misc.
Any/top-level map handling.
Refs: #2950 (kotlinx fixture coverage, where the skips live), #2845 (Kotlin date-time support + kotlinx KSerializer pattern).
Summary
The Kotlin kotlinx-serialization renderer (
--framework kotlinx) does not implement union serialization.KotlinXRenderer.tsopens with:The base Kotlin renderer emits unions as a sealed class with wrapper members:
Klaxon and Jackson make this work with hand-written converters that inspect the raw JSON and pick the matching member. The kotlinx renderer emits only the bare
@Serializablesealed class — and kotlinx-serialization's default handling for sealed classes is discriminated polymorphism, expecting{"type": ..., ...}objects. The actual JSON for a quicktype union is the bare value itself (e.g."quux"or3.14), so decoding throws at runtime and encoding produces the wrong shape.Impact
test/inputs/schema/date-time-or-string.schema, the propertybar: oneOf [date-time, enum]used to collapse to plainString(no date-time type ⇒ string absorbed the union) but now becomes a genuinedate-time | enumunion, sodate-time.schemaanddate-time-or-string.schemaalso have to stay skipped for kotlinx.keyword-unions.schemais additionally blocked by a synthesized-constructor >255-parameter JVM limit.Proposed fix
Emit a custom
KSerializer<XUnion>per union that dispatches on JSON shape (JsonPrimitive/string/number/boolean/JsonObject/JsonArray, withisStringetc. to disambiguate), mirroring the member-matching logic (and match priority) that the klaxon/jackson converters use, and register it via@Serializable(with = ...)on the sealed class. The@file:UseSerializers+ same-file serializer pattern introduced for date/time serializers in #2845 can be extended for this.Acceptance: lift the union-related skips in
test/languages.tsforKotlinXLanguage(JSON union inputs,union.schemaet al.,date-time.schema,date-time-or-string.schema) and claim theunionfeature so the.fail.union.jsonsamples run.Related gaps (same TODO line, possibly separate follow-ups)
typealias TopLevel = JsonArray<T>, which does not compile (JsonArraytakes no type parameters) — currently 40 JSON inputs +union.schemaskipped, and77392.json/b4865.jsonin misc.Any/top-level map handling.Refs: #2950 (kotlinx fixture coverage, where the skips live), #2845 (Kotlin date-time support + kotlinx KSerializer pattern).
🤖 Generated with Claude Code