Skip to content

Disable Json.NET metadata special handling#3090

Merged
jar-stripe merged 3 commits intomasterfrom
jar/ignore-metadata-when-reading-json
Apr 4, 2025
Merged

Disable Json.NET metadata special handling#3090
jar-stripe merged 3 commits intomasterfrom
jar/ignore-metadata-when-reading-json

Conversation

@jar-stripe
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe commented Apr 4, 2025

Why?

#3068 reported a persistent issue with parsing API responses in Stripe.net. The example posted shows a "$ref" key in the metadata of the returned payment_intent object. Newtonsoft Json.NET has support for object references, in which case it interprets an JSON object string with only "$ref" key as a reference to an object defined elsewhere in the JSON. Json.NET requires reference objects contain only the single "$ref" key; because the metadata object in the failure case had additional keys, Json.NET throws an exception.

Stripe.net does not write object references nor does it use Json.NET metadata to parse responses from Stripe's API, so this PR configures our Json deserialization to ignore handling metadata properties specially.

What?

  • added MetadataPropertyHandling = MetadataPropertyHandling.Ignore in DefaultSerializerSettings
  • added test to confirm reference objects are ignored

See Also

…efaultSerializerSettings

added test to confirm reference objects are ignored
@jar-stripe jar-stripe marked this pull request as ready for review April 4, 2025 22:20
@jar-stripe jar-stripe requested a review from a team as a code owner April 4, 2025 22:20
@jar-stripe jar-stripe requested review from mbroshi-stripe and removed request for a team April 4, 2025 22:20
@jar-stripe jar-stripe changed the title Ignore Json.NET metadata special handling Disable Json.NET metadata special handling Apr 4, 2025
@jar-stripe jar-stripe enabled auto-merge (squash) April 4, 2025 23:30
@jar-stripe jar-stripe merged commit 09fd4b2 into master Apr 4, 2025
4 checks passed
@jar-stripe jar-stripe deleted the jar/ignore-metadata-when-reading-json branch April 4, 2025 23:37
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