Repository navigation
fix: use field-presence checks in union deserializers to prevent misclassification - #25
Merged
Merged
Conversation
…lassification Previously, all union response deserializers attempted blind `convertValue` calls in sequence, catching `RuntimeException` to fall through to the next candidate type. This approach could silently misclassify a response payload as the wrong union variant when Jackson's lenient conversion succeeded on an incompatible type. The deserializers now inspect the raw `Map` keys first, requiring the presence of discriminating fields before attempting conversion. This makes variant selection deterministic and prevents incorrect deserialization of ambiguous payloads. Key changes: - `GetAggregationCountResponse` and `PostAggregationCountResponse` deserializers now gate on `status`, `total_hits`, `page`, `total_pages`, and `page_size` keys before attempting conversion to `AggregationCountResponseDto` or `FailedAggregationCountResponseDto` - `GetAuthorsResponse` and `PostAuthorsResponse` deserializers apply the same pagination-field guard before converting to `SearchResponseDto` or `FailedAuthorsResponseDto` - `GetLatestHeadlinesResponse`, `PostLatestHeadlinesResponse`, `GetSearchResponse`, and `PostSearchResponse` deserializers additionally require `clusters_count` and `clusters` keys before attempting `ClusteredSearchResponseDto` conversion - `AggregationCountResponseDtoAggregations` deserializer gates on `aggregation_count` key before attempting `AggregationItem` conversion - `SourcesResponseDtoSourcesItem` deserializer gates on `domain_url` key before attempting `SourceInfo` conversion 🌿 Generated with Fern
oscatcher
self-requested a review
May 1, 2026 15:10
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.
2.1.0 → 2.1.1
Previously, all union response deserializers attempted blind
convertValuecalls in sequence, catching
RuntimeExceptionto fall through to the nextcandidate type. This approach could silently misclassify a response payload
as the wrong union variant when Jackson's lenient conversion succeeded on an
incompatible type.
The deserializers now inspect the raw
Mapkeys first, requiring thepresence of discriminating fields before attempting conversion. This makes
variant selection deterministic and prevents incorrect deserialization of
ambiguous payloads.
Key changes:
GetAggregationCountResponseandPostAggregationCountResponsedeserializers now gate onstatus,total_hits,page,total_pages, andpage_sizekeys before attempting conversion toAggregationCountResponseDtoorFailedAggregationCountResponseDtoGetAuthorsResponseandPostAuthorsResponsedeserializers apply the same pagination-field guard before converting toSearchResponseDtoorFailedAuthorsResponseDtoGetLatestHeadlinesResponse,PostLatestHeadlinesResponse,GetSearchResponse, andPostSearchResponsedeserializers additionally requireclusters_countandclusterskeys before attemptingClusteredSearchResponseDtoconversionAggregationCountResponseDtoAggregationsdeserializer gates onaggregation_countkey before attemptingAggregationItemconversionSourcesResponseDtoSourcesItemdeserializer gates ondomain_urlkey before attemptingSourceInfoconversion🌿 Generated with Fern