Enhance JSON unmarshalling in CallDestination to support dynamic transfer types (number and sip) with additional fields handling. #9
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.
Fix CallDestination UnmarshalJSON for Transfer Responses
Problem
The
CallDestination.UnmarshalJSONmethod was failing to properly deserialize transfer responses withtype: "number"when the API response included additional fields not present in the generatedTransferDestinationNumberstruct.Root Cause
The Fern-generated
TransferDestinationNumberstruct has a specific set of fields:Number(required)Message(optional, of type*TransferDestinationNumberMessage)NumberE164CheckEnabled(optional, of type*bool)However, the API response for transfer destinations with
type: "number"can include additional fields like:transferPlan(map[string]interface{})The original code attempted to unmarshal directly into
TransferDestinationNumber, which would fail when these extra fields were present.Solution
Modified the
UnmarshalJSONmethod incalls.goto:type: "number"early in the deserialization processTransferDestinationNumberstructTransferDestinationNumberinstance with the extracted dataKey Changes
messagefield by attempting to unmarshal it asTransferDestinationNumberMessageNumberE164CheckEnabledoptional and properly typed as*boolTesting
The fix has been tested to:
go build ./...TransferDestinationNumberstructImpact
This fix resolves the deserialization issue for transfer responses while maintaining the integrity of the generated SDK structure. The change is minimal and focused, affecting only the specific case where transfer responses with
type: "number"include additional fields.Related Issues
This addresses the problem where users were getting deserialization errors when the API returned transfer responses that included fields beyond what the generated struct expected. #8