Skip to content

fix: preserve Kotlin mixed-object additional properties - #180

Merged
adamcavendish merged 1 commit into
mainfrom
adamcavendish/kotlin-additional-properties
Nov 12, 2026
Merged

adamcavendish merged 1 commit into
mainfrom
adamcavendish/kotlin-additional-properties

Conversation

@adamcavendish

@adamcavendish adamcavendish commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Preserve explicitly declared additional properties in Kotlin OkHttp objects that
also have named fields, including typed values and opaque JSON trees.

Problem

The IR retained mixed-object extension facts, but Kotlin emitted only named
properties. Ordinary Gson decoding and re-encoding silently discarded extension
entries. Pure dictionaries were already repaired in #177 and are unchanged here.

Behavior

Situation Behavior
Explicit mixed-object extras Defaulted typed mutable storage, flattened to wire object keys
Opaque extension values Verbatim keys, JSON nulls and exact numeric literals
Typed values and containers Existing model, enum, alias, recursive and union codecs
Data-class copy and components Normal shallow copy retains extras; named positions unchanged
Declared-key collisions Reject writes, including omitted or configured named fields
Storage or helper-name clashes Suffix generated names without renaming authored declarations
Configured Gson and HTTP paths Preserve named delegates, value adapters and typed payloads

Compatibility

Existing named constructor arguments remain valid, and secondary constructors
retain the old Java named-field entrypoints. The appended property participates
in equality, hash and component operations. It changes data-class binary
signatures: regenerate and recompile consumers instead of mixing SDK binaries.

Named fields retain native streaming/tree coercion differences, configured numeric
output and ordinary null omission. Extension null handling restores surrounding
writer settings even on failure. The runtime uses Gson 2.11.0 tree-reader/writer
implementation classes; generated dependencies are unchanged.

Only Kotlin mixed objects with explicit additional-property facts are repaired.
Pure dictionaries, closed/implicit objects, shared lowering, other languages,
opaque named-alias codecs, multi-member allOf, tagged-wrapper extension storage
and generation formatting remain separate.

- Retain explicit typed extension values in objects with named properties instead
  of silently discarding them through named-field-only Gson models.
- Append defaulted mutable storage to data-class constructors so ordinary shallow
  copies, equality and components retain extras without shifting named components.
- Keep named constructor arguments and old Java constructor entrypoints available,
  while documenting the need to recompile consumers after binary signatures change.
- Flatten verbatim extension keys with opaque JSON precision and nulls while
  retaining declared model, enum, nullable, container, alias and recursive codecs.
- Disambiguate storage and private factory names against authored declarations and
  reject extension keys that would overwrite declared or configured wire fields.
- Reuse configured Gson delegates for named fields, preserving native stream/tree
  coercion, numeric output and ordinary null omission without leaking writer state.
- Retain typed HTTP request, success and lazy error payloads alongside native
  consumer contracts and exact render and golden coverage.
- Keep pure dictionaries, shared lowering, other languages, opaque-alias codecs,
  allOf, tagged-wrapper extension storage and generation formatting separate.
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.30996% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../generators/kotlin/okhttp/additional_properties.rs 95.79% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adamcavendish
adamcavendish merged commit b99a0a2 into main Nov 12, 2026
31 checks passed
@adamcavendish
adamcavendish deleted the adamcavendish/kotlin-additional-properties branch November 12, 2026 18:21
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.

1 participant