Skip to content

fix: preserve Java additional properties - #179

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

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

Conversation

@adamcavendish

Copy link
Copy Markdown
Collaborator

Summary

Preserve explicit additional properties in Java OkHttp models, including pure
dictionaries and objects with named fields.

Problem

The IR retains additional-value types, but Java object emission used only named
properties. Gson therefore silently dropped mixed-object extensions and turned
pure dictionaries into empty objects.

Behavior

Models expose typed, mutable getAdditionalProperties() storage with an independent
empty-map default. Existing named constructors and getters stay unchanged.

MixedMap value = new MixedMap("fixed");
value.getAdditionalProperties().put("keep_key", new NestedValue("nested"));
// Gson writes {"known_field":"fixed","keep_key":{"wire_value":"nested"}}
Situation Behavior
Pure dictionary Normal model with flat entries, not a Map subtype
Opaque values JsonElement preserves trees, nulls and numeric precision
Typed values Declared Gson codecs retain models, aliases and policies
Extension keys Stay verbatim rather than following Java field renaming
Storage collision Numeric suffix keeps authored fields and getters intact
Declared-key clash IllegalArgumentException, even for omitted named fields

Configured Gson delegates still own ordinary fields. Native streaming/tree
integer behavior, custom field/value adapters, configured numeric writing and
ordinary null omission remain intact. Extension null preservation restores the
surrounding writer setting even on failure. HTTP JSON requests, successful
responses and lazy typed-error bodies retain their dictionary entries.

Boundaries

Java OkHttp only. Closed/implicit models, alias wrappers, generated dependency
versions, shared lowering and other-language generators are unchanged. General
inline union type loss, primitive-union helper-name collisions, multi-member
allOf and tagged-wrapper extension storage remain separate repairs.

The support uses tree-reader/writer implementation classes from the unchanged
Gson 2.11.0 dependency to retain its native input/output behavior. Native consumers
cover both tree and streaming entrypoints. Ordinary fields are buffered for their
configured delegate rather than reimplemented as a new validation policy.

Generation formatting remains a separate recorded follow-up; this PR does not
add a formatter or claim generated-source formatter conformance.

- Retain explicit typed extension values in mixed objects and pure dictionaries
  instead of silently discarding them through named-field-only Gson models.
- Expose independent mutable storage through getAdditionalProperties without
  changing named constructor parameters or making dictionary models Map subtypes.
- Flatten extension entries with verbatim keys, opaque JSON precision and nulls,
  while retaining declared model, enum, alias, container and recursive codecs.
- Disambiguate storage/getter names and reject extension keys that would overwrite
  declared wire fields, including omitted fields and configured Gson field names.
- Delegate ordinary fields through the configured Gson instance, preserving native
  streaming/tree coercion differences, numeric output and surrounding null policy.
- Qualify helper and value identities against authored model names and retain
  native HTTP request, success and lazy typed-error dictionary payloads.
- Keep shared lowering, union-decoder naming defects, other languages, allOf,
  tagged-wrapper extension storage and generation formatting outside this repair.
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.05882% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rc/generators/java/okhttp/additional_properties.rs 96.57% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adamcavendish
adamcavendish merged commit bfc7733 into main Nov 12, 2026
31 checks passed
@adamcavendish
adamcavendish deleted the adamcavendish/java-additional-properties branch November 12, 2026 17: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