Skip to content

Fix emptyable property serialization for third-party serializers#3366

Merged
jar-stripe merged 2 commits intomasterfrom
jar/emptyable-serialization-fix
Apr 15, 2026
Merged

Fix emptyable property serialization for third-party serializers#3366
jar-stripe merged 2 commits intomasterfrom
jar/emptyable-serialization-fix

Conversation

@jar-stripe
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe commented Apr 14, 2026

Why?

See #3364. When a third-party serializer (e.g. AWS Lambda) serializes an Options object, unset emptyable properties were written as "mandate_data": null. On deserialization the setter fires, SetTracker.Track() marks the property as explicitly set, and the SDK sends mandate_data= to the API — unintentionally clearing fields.

The risk extends beyond Create calls — on Update APIs this could silently clear fields like invoice_settings without the user realizing.

What?

  • Regenerated Options classes with NullValueHandling.Ignore (Newtonsoft) and WhenWritingNull (STJ) annotations on emptyable properties, so third-party serializers skip unset nulls
  • Refactored STJDefaultConverter.Write null-handling to dispatch on the property's ignore condition: WhenWritingNull properties only write null when IsPropertySet is true
  • Added round-trip serialization tests covering both Newtonsoft and STJ paths
  • Updated TestOptions to match the new codegen output

See Also

Changelog

  • Fixes a bug where serializing Options objects through a third-party serializer (e.g. AWS Lambda) could cause the SDK to unintentionally clear fields on the API. Emptyable properties now have null-skipping annotations so third-party serializers omit unset properties during round-trips.

jar-stripe and others added 2 commits April 13, 2026 17:44
Regenerated from sdk-codegen jar/emptyable-serialization-fix branch.
Emptyable properties now have NullValueHandling.Ignore (Newtonsoft) and
JsonIgnoreCondition.WhenWritingNull (STJ) annotations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Fixes #3364. When a third-party serializer (e.g. AWS
Lambda) serialized an Options object, unset emptyable properties were
written as null. On deserialization the setter fired, SetTracker marked
the property as explicitly set, and the SDK sent empty-string values to
the API — unintentionally clearing fields.

The fix is on the serialization side: emptyable properties now have
NullValueHandling.Ignore and WhenWritingNull annotations (via codegen),
so third-party serializers skip unset nulls.

Also refactors STJDefaultConverter.Write to make the null-handling logic
clearer: WhenWritingNull properties only write null when IsPropertySet
is true, other properties follow the standard ignore condition.

Adds round-trip tests covering Newtonsoft and STJ serialization paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
@jar-stripe jar-stripe marked this pull request as ready for review April 15, 2026 22:54
@jar-stripe jar-stripe requested a review from a team as a code owner April 15, 2026 22:54
@jar-stripe jar-stripe requested review from xavdid and removed request for a team April 15, 2026 22:54
Copy link
Copy Markdown
Member

@xavdid xavdid left a comment

Choose a reason for hiding this comment

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

fix looks good, but make sure to call out this behavior / pitfalls in the README!

@jar-stripe jar-stripe merged commit 04a1df3 into master Apr 15, 2026
15 checks passed
@jar-stripe jar-stripe deleted the jar/emptyable-serialization-fix branch April 15, 2026 23:16
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.

2 participants