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

Don't try to serialize the DynamicApi property #2578

Merged
merged 7 commits into from
Aug 25, 2021
Merged

Conversation

nirinchev
Copy link
Member

@nirinchev nirinchev commented Aug 23, 2021

Description

This replaces [XmlIgnore] with [IgnoreDataMember] as that works for both the Xml and Json serializer. It removes [Serializable] as that was only used in the BinarySerializer which is very strongly obsoleted.

Finally, it annotates the RealmCollectionBase properties with [IgnoreDataMember] to make sure a json serializer doesn't try to touch them and adds tests for both Xml and Json serialization.

A couple of caveats:

  1. Newtonsoft.Json doesn't work on Unity out of the box, so we only test on the other platforms.
  2. MongoDB.Bson and XmlSerializer don't serialize collections by default, so we're not validating it.

Fixes #2579

TODO

  • Changelog entry
  • Tests (if applicable)

@nirinchev nirinchev self-assigned this Aug 23, 2021
@@ -39,17 +41,20 @@ public abstract class RealmCollectionBase<T>
IThreadConfined,
IMetadataObject
{
private readonly List<NotificationCallbackDelegate<T>> _callbacks = new List<NotificationCallbackDelegate<T>>();
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, this change also reorders the members of RealmCollectionBase because they were all over the place. Apart from the reordering, the only other change is the addition of the attributes.

public abstract class RealmObjectBase
: INotifyPropertyChanged,
IThreadConfined,
INotifiable<NotifiableObjectHandleBase.CollectionChangeSet>,
IReflectableType
{
[NonSerialized, XmlIgnore]
Copy link
Member Author

Choose a reason for hiding this comment

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

The Xml serializer ignores the private/internal fields anyway.

@nirinchev nirinchev marked this pull request as ready for review August 25, 2021 12:36
@nirinchev nirinchev merged commit e3cec7f into master Aug 25, 2021
@nirinchev nirinchev deleted the ni/fix-serialization branch August 25, 2021 13:42
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore base properties when serializing RealmObjects
2 participants