Skip to content

Commit

Permalink
Add more serializer types to the preserved ones (#2489)
Browse files Browse the repository at this point in the history
* Add more serializer types to the preserved ones

* Add changelog
  • Loading branch information
nirinchev authored Jul 1, 2021
1 parent d7d15e5 commit 19d4a60
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fixed a crash after clearing a list or set of Mixed containing links to objects. (Core upgrade)
* Fixed a recursive loop which would eventually crash trying to refresh a user app token when it had been revoked by an admin. Now this situation logs the user out and reports an error. (Core upgrade)
* Fixed a race between calling `Realm.DeleteRealm` and concurrent opening of the realm file. (Core upgrade)
* \[Unity\] Added code to preserve the constructors of several base serializers to ensure that most of the basic serialization/deserialization workloads work out of the box. (PR [#2489](https://github.com/realm/realm-dotnet/pull/2489))

### Enhancements
* Changed the native iOS library to use xcframework. This means that running in the simulator on M1 macs is now supported. (Issue [#2240](https://github.com/realm/realm-dotnet/issues/2240))
Expand Down
47 changes: 45 additions & 2 deletions Realm/Realm/Helpers/SerializationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,33 @@ internal static class SerializationHelper

static SerializationHelper()
{
var decimalSerializer = new DecimalSerializer(BsonType.Decimal128, new RepresentationConverter(allowOverflow: false, allowTruncation: false));
BsonSerializer.RegisterSerializer(decimalSerializer);
BsonSerializer.RegisterSerializer(new DecimalSerializer(BsonType.Decimal128, new RepresentationConverter(allowOverflow: false, allowTruncation: false)));
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
BsonSerializer.RegisterSerializer(new DateTimeOffsetSerializer(BsonType.String));
}

[Preserve]
internal static void PreserveSerializers()
{
_ = new BooleanSerializer();
_ = new ByteSerializer();
_ = new CharSerializer();
_ = new Int16Serializer();
_ = new Int32Serializer();
_ = new Int64Serializer();
_ = new SingleSerializer();
_ = new DoubleSerializer();
_ = new DecimalSerializer();
_ = new Decimal128Serializer();
_ = new ObjectIdSerializer();
_ = new GuidSerializer();
_ = new DateTimeSerializer();
_ = new DateTimeOffsetSerializer();
_ = new StringSerializer();
_ = new ByteArraySerializer();

_ = new EnumSerializer<Credentials.AuthProvider>();

_ = new ArraySerializer<bool>();
_ = new ArraySerializer<byte>();
_ = new ArraySerializer<char>();
Expand All @@ -56,6 +77,28 @@ static SerializationHelper()
_ = new ArraySerializer<Guid>();
_ = new ArraySerializer<DateTime>();
_ = new ArraySerializer<DateTimeOffset>();
_ = new ArraySerializer<string>();
_ = new ArraySerializer<byte[]>();

_ = new NullableSerializer<bool>();
_ = new NullableSerializer<byte>();
_ = new NullableSerializer<char>();
_ = new NullableSerializer<short>();
_ = new NullableSerializer<int>();
_ = new NullableSerializer<long>();
_ = new NullableSerializer<float>();
_ = new NullableSerializer<double>();
_ = new NullableSerializer<decimal>();
_ = new NullableSerializer<Decimal128>();
_ = new NullableSerializer<ObjectId>();
_ = new NullableSerializer<Guid>();
_ = new NullableSerializer<DateTime>();
_ = new NullableSerializer<DateTimeOffset>();

_ = new BsonDocumentSerializer();
_ = new BsonArraySerializer();

_ = new ObjectSerializer();
}

public static string ToNativeJson(this object value)
Expand Down

0 comments on commit 19d4a60

Please sign in to comment.