Repository navigation
fix: preserve Java untagged-union member payloads - #175
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
- Select Java OkHttp union members using retained finite scalar and structural facts so unconstrained Gson fields cannot swallow another member's payload. - Expose firstMatch, strict, and explicit raw policies while keeping typed sealed interfaces, record payloads, and existing root-null behavior by default. - Count original concrete members before opaque fallbacks and decode the selected member once, preserving nested strict errors and authored wrapper boundaries. - Compare exact significands and unbounded exponents instead of Gson's scale- limited decimal accessor, without rounding or hiding native decoder failures. - Memoize recursive predicates by JSON node identity with qualified boxed types, retaining failed matches and models named Integer or Boolean without collisions. - Preserve complete raw JSON trees, including null entries and large numbers, without leaking a changed null policy into ordinary sibling serialization. - Build adapter declarations with TypeSpec and semantic fields, methods and types, limiting the unsupported final-class modifier escape to its single token. - Keep ordinary and tagged codecs unchanged and exercise generated model and OkHttp response/error consumers through independent native policy projects.
adamcavendish
force-pushed
the
adamcavendish/java-untagged-union-selection
branch
from
November 11, 2026 12:51
22a1086 to
87660a3
Compare
adamcavendish
deleted the
adamcavendish/java-untagged-union-selection
branch
November 11, 2026 13:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Preserve Java OkHttp untagged-union member payloads with enum-aware structural
selection and configurable typed or raw adapters.
Problem
The existing Gson adapter chooses named object members by required keys alone.
Members with the same required keys but disjoint numeric enums therefore select
the first variant and silently discard fields from the actual matching member.
The same loss occurs through containing model fields, lists, and maps.
Behavior
firstMatch(default)strictrawVariantRaw(JsonElement)and preserve known, ambiguous, unmatched, null JSON.Typed selection uses finite scalar constraints, required wire keys, nested
containers, and recursive schema facts. Numeric comparisons retain large-integer
distinctions and match scientific notation through exact significands and
unbounded exponents, without Gson's decimal-accessor scale limit. Each selected
member is decoded once through its original Gson codec; nested errors and native
decoder limits are not hidden by another member or fallback. Recursive matching
reuses both successful and failed results within one selection, with private
runtime types qualified against generated model-name collisions.
These adapters also apply to HTTP response bodies and lazily decoded typed error
bodies. Raw serialization retains null-valued entries without changing the
surrounding Gson writer's null policy.
Compatibility
payload types, serialization, and typed root-null behavior. Explicit raw mode
changes the union API to a raw record case; colliding case names are disambiguated.
unchanged. Selection is not full JSON Schema validation and does not redefine
native format, numeric-bound, coercion, or overflow behavior.
separate repairs. Kotlin and all other language generators remain unchanged.