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

Enable ignoring fields by using [NonSerialized] #1808

Merged
merged 1 commit into from Apr 24, 2024

Conversation

mookid8000
Copy link
Contributor

MessagePack-CSharp is nice enough to simply skip serialization of properties and fields tagged with [IgnoreDataMember] and [IgnoreMember] without fuzz, which seems appropriate.

Since .NET also contains the [NonSerialized] attribute, which I believe is the oldest "dear serializer, please ignore this field"-type of serializer hint, it seems natural to also ignore these. This will in turn make migration from the old BinaryFormatter (which is deprecated and no longer exists in .NET 9) much easier, because [NonSerialized] was how it was told to skip specific fields.

This PR adds an extra case to the CreateEmittableMember method of DynamicObjectResolver, which causes fields decorated with [NonSerialized] to be ignored. It's backed up by an additional test Serialize_WithNonSerializedAttribute in DataContractTest.

Copy link
Collaborator

@AArnott AArnott left a comment

Choose a reason for hiding this comment

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

Looks great. Thank you for the PR and the test.

@AArnott AArnott merged commit 76cc9a3 into MessagePack-CSharp:master Apr 24, 2024
5 of 6 checks passed
@AArnott AArnott added this to the v2.5 milestone Apr 24, 2024
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.

None yet

2 participants