Skip to content

Design a dependency-free four-state JSON field model for generated types #50

Description

@OmarAlJarrah

Problem

A generator needs a field wrapper distinguishing present-typed, present-but-wrong-type, explicit-null, and absent — and round-tripping unknown shapes. Tristate covers three states (absent/null/present) but has no raw/wrong-type escape hatch and no embedded JSON tree.

Proposed change

Design a dep-free sealed JsonField<T> (Known<T:Any> / Missing / Null / Raw(RawJson)) plus a RawJson tree (object/array/string/number/bool/null) in sdk-core, with all Jackson↔RawJson conversion behind the Serde SPI in the adapter — mirror how Tristate is split. Map Tristate onto it. Kotlin sealed class compiles to Java-8 bytecode (no permits).

Prior art: openai-java's JsonField/JsonValue (Values.kt) — but it welds Jackson onto the value type; we must not. Reuse the contextual-type-extraction trick from our TristateModule.

Acceptance

  • Dep-free JsonField + RawJson in core
  • Jackson conversion in adapter only
  • Tristate interop documented, incl. the read-path (forward-compat) vs PATCH-path (three-state) boundary so the two are never wrongly merged
  • apiDump

Foundation for the rest of the codegen items.

Dependencies


Priority: highest · Effort: large

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenfuture KotlinPoet codegenenhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions