Skip to content

Fixes STJDefaultConverter to safely ignore unknown properties#3223

Merged
jar-stripe merged 1 commit intomasterfrom
jar/stj-safely-ignore-undocumented-properties
Oct 15, 2025
Merged

Fixes STJDefaultConverter to safely ignore unknown properties#3223
jar-stripe merged 1 commit intomasterfrom
jar/stj-safely-ignore-undocumented-properties

Conversation

@jar-stripe
Copy link
Copy Markdown
Contributor

Why?

There is a bug in STJDefaultConverter where extra properties in the JSON could cause an exception when it is being deserialized. We currently do not support capturing extra properties into a separate object with STJ (like we do with Newtonsoft Json.NET) so for now we can safely discard these properties.

What?

  • fixes STJDefaultConverter to advance the reader even if the property is not present in the type being deserialized
  • changes loop to find the target property to a Filter call, for readability

See Also

Changelog

  • Fixes a bug when using System.Text.Json to deserialize JSON that has properties not present in the target object.

…is not known

changed loop to a filter call for clarity
@jar-stripe jar-stripe requested a review from a team as a code owner October 14, 2025 23:47
@jar-stripe jar-stripe requested review from helenye-stripe and removed request for a team October 14, 2025 23:47
Copy link
Copy Markdown
Contributor

@prathmesh-stripe prathmesh-stripe left a comment

Choose a reason for hiding this comment

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

I'll follow this up with a test case.

@jar-stripe jar-stripe merged commit f938c17 into master Oct 15, 2025
7 checks passed
@jar-stripe jar-stripe deleted the jar/stj-safely-ignore-undocumented-properties branch October 15, 2025 00:34
jar-stripe added a commit that referenced this pull request Oct 21, 2025
* update doc link (#3212)

* Improve event notification example (#3217)

* improve events example

* update docs

* added .net 9 to target frameworks
excluded deprecated code in SystemNetHttpClient for .net 9 and above
added justfile and script to install required sdk versions
updated test commands to use .net 9 target (in justfile)
deleted global.json
updated build step in ci to read target frameworks from the project file

* Revert "added .net 9 to target frameworks"

This reverts commit 26a197a.

* fixed STJDefaultConverter to advance the reader even if the property is not known (#3223)

changed loop to a filter call for clarity

* Added STJ tests for deserializing null values (#3224)

* Add support for building on .NET 9 (#3222)

---------

Co-authored-by: David Brownman <109395161+xavdid-stripe@users.noreply.github.com>
Co-authored-by: Prathmesh Ranaut <165320323+prathmesh-stripe@users.noreply.github.com>
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