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

Add OnSerialize callbacks to POCOs #54709

Merged
merged 5 commits into from
Jul 9, 2021
Merged

Conversation

steveharter
Copy link
Member

@steveharter steveharter commented Jun 24, 2021

Resolves #54528

Does not measurable affect performance; the is IJsonSerializable etc C# calls appear to be the same performance as a standard "if (bool)" check after a few runs.

This does not include the work necessary for source-gen.

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Jun 24, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

Resolves #54528

Does not measurable affect performance; the is IJsonSerializable etc C# calls appear to be the same performance as a standard "if (bool)" check after a few runs.

Author: steveharter
Assignees: steveharter
Labels:

area-System.Text.Json

Milestone: 6.0.0

}

[Fact]
public static void NonPocosIgnored()
Copy link
Member

Choose a reason for hiding this comment

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

What prevents us from supporting callbacks in collection types?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing (same for value types) although there are very limited scenarios for both since custom converters would normally be used which implicitly have support for before\after.

Also, a richer interaction model would be better for collections - in order to provide support for "Add()" as well as holding onto any temporary collections needed for things like Arrays, Stacks and immutable collections.

/// </summary>
/// <remarks>
/// This behavior is only supported on types representing JSON objects.
/// Types that have a custom converter or represent collections or values do not support this behavior.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is this more clear?

Suggested change
/// Types that have a custom converter or represent collections or values do not support this behavior.
/// Types that have a custom converter or represent collections or primitive values do not support this behavior.

@steveharter
Copy link
Member Author

Test failures in mono arm64 Debug appear unrelated:

Work item System.Buffers.Tests
Work item System.Collections.Tests

@steveharter steveharter merged commit b814a97 into dotnet:main Jul 9, 2021
@steveharter steveharter deleted the PocoCallbacks branch July 9, 2021 15:45
@ghost ghost locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for POCO serialization callbacks
3 participants