Skip to content

fix: use field-presence checks in union deserializers to prevent misclassification - #25

Merged
oscatcher merged 2 commits into
mainfrom
fern-bot/2026-04-30T13-03Z
May 1, 2026
Merged

oscatcher merged 2 commits into
mainfrom
fern-bot/2026-04-30T13-03Z

Conversation

@fern-api

@fern-api fern-api Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

2.1.0 → 2.1.1

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

…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
oscatcher self-requested a review May 1, 2026 15:10

@oscatcher oscatcher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@oscatcher
oscatcher merged commit f31976b into main May 1, 2026
3 checks passed
@oscatcher
oscatcher deleted the fern-bot/2026-04-30T13-03Z branch May 1, 2026 16:07
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