Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify JsonSerializationOptions instead of creating a new instance #2651

Merged

Conversation

mmsmits
Copy link
Member

@mmsmits mmsmits commented Jan 3, 2024

fixes: #2583

@mmsmits mmsmits changed the title fix: modify JsonSerializationOptions instead of creating an new instance Modify JsonSerializationOptions instead of creating an new instance Jan 3, 2024
@mmsmits mmsmits changed the title Modify JsonSerializationOptions instead of creating an new instance Modify JsonSerializationOptions instead of creating a new instance Jan 5, 2024
Copy link
Member

@ewoutkramer ewoutkramer left a comment

Choose a reason for hiding this comment

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

There is a ForFhir<F> just below that has the same problem.

More in general, we create & return new options, which does not work well with the ASP.NET service configuration pattern, e.g. see here: https://www.meziantou.net/configuring-json-options-in-asp-net-core.htm

Pretty() and Compact() will have the same problems. Thinking about this a bit more, changing this could be considered a breaking change, since we're suddenly changing the input parameter, which is probably unexpected.

What to do about that?

…instead-of-creating-new' into bugfix/2583-modify-json-options-instead-of-creating-new
ewoutkramer
ewoutkramer previously approved these changes Jan 9, 2024
@@ -41,7 +41,8 @@ public void RoundtripEdgeCases()
{
var (poco, expected) = getEdgecases();

var options = BaseOptions.Pretty();
var options = new JsonSerializerOptions().ForFhir(typeof(TestPatient).Assembly).Pretty();
Copy link
Member

Choose a reason for hiding this comment

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

This is exactly why this could be considered a breaking change, as we discussed on our call. Still, the benefits for the use in service initialization outweigh the risk I think. And I guess many people even assume we return the same instance (but then modified). But we cannot be sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add something to the release notes

@ewoutkramer ewoutkramer merged commit 4be8199 into develop Jan 10, 2024
15 checks passed
@ewoutkramer ewoutkramer deleted the bugfix/2583-modify-json-options-instead-of-creating-new branch January 10, 2024 10:30
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.

ModelBinding fails with Error ... Patient is abstract .... could not be instantiated and populated
2 participants