diff --git a/src/common.props b/src/common.props index 9f3fc117438..204d9d08822 100644 --- a/src/common.props +++ b/src/common.props @@ -13,7 +13,7 @@ 2.4.1 2.4.3 17.0.0 - 0.12.0 + 0.12.2 [12.0.3,) 2.0.1 3.19.4 diff --git a/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionConfigTests.cs b/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionConfigTests.cs index 33f8ccd1f84..8894886ef63 100644 --- a/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionConfigTests.cs +++ b/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionConfigTests.cs @@ -93,12 +93,14 @@ public void TypeFilter_defined_in_config_should_filter_serializer_properly(objec "); using (var system = ActorSystem.Create(nameof(HyperionConfigTests), config)) { - var serializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object)); + var deserializer = (HyperionSerializer)system.Serialization.FindSerializerForType(typeof(object)); + var serializer = new HyperionSerializer(null, deserializer.Settings.WithDisallowUnsafeType(false)); - ((TypeFilter)serializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2); + ((TypeFilter)deserializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2); + var serialized = serializer.ToBinary(sampleObject); object deserialized = null; - Action act = () => deserialized = serializer.FromBinary(serialized); + Action act = () => deserialized = deserializer.FromBinary(serialized); if (shouldSucceed) { act.Should().NotThrow(); diff --git a/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionSerializerSetupSpec.cs b/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionSerializerSetupSpec.cs index a5e0cc8be2e..021623632d0 100644 --- a/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionSerializerSetupSpec.cs +++ b/src/contrib/serializers/Akka.Serialization.Hyperion.Tests/HyperionSerializerSetupSpec.cs @@ -130,9 +130,10 @@ public void Setup_surrogate_should_work() [MemberData(nameof(DangerousObjectFactory))] public void Setup_disallow_unsafe_type_should_work(object dangerousObject, Type type) { - var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, HyperionSerializerSettings.Default); + var deserializer = new HyperionSerializer((ExtendedActorSystem)Sys, HyperionSerializerSettings.Default); + var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, deserializer.Settings.WithDisallowUnsafeType(false)); var serialized = serializer.ToBinary(dangerousObject); - serializer.Invoking(s => s.FromBinary(serialized, type)).Should().Throw(); + deserializer.Invoking(s => s.FromBinary(serialized, type)).Should().Throw(); } [Theory] @@ -146,12 +147,13 @@ public void Setup_TypeFilter_should_filter_types_properly(object sampleObject, b .Build()); var settings = setup.ApplySettings(HyperionSerializerSettings.Default); - var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, settings); - - ((TypeFilter)serializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2); + var deserializer = new HyperionSerializer((ExtendedActorSystem)Sys, settings); + var serializer = new HyperionSerializer((ExtendedActorSystem)Sys, deserializer.Settings.WithDisallowUnsafeType(false)); var serialized = serializer.ToBinary(sampleObject); + + ((TypeFilter)deserializer.Settings.TypeFilter).FilteredTypes.Count.Should().Be(2); object deserialized = null; - Action act = () => deserialized = serializer.FromBinary(serialized); + Action act = () => deserialized = deserializer.FromBinary(serialized); if (shouldSucceed) { act.Should().NotThrow(); diff --git a/src/contrib/serializers/Akka.Serialization.Hyperion/HyperionSerializer.cs b/src/contrib/serializers/Akka.Serialization.Hyperion/HyperionSerializer.cs index b05f0cc3b50..dc525668441 100644 --- a/src/contrib/serializers/Akka.Serialization.Hyperion/HyperionSerializer.cs +++ b/src/contrib/serializers/Akka.Serialization.Hyperion/HyperionSerializer.cs @@ -401,5 +401,75 @@ public HyperionSerializerSettings( DisallowUnsafeType = disallowUnsafeType; TypeFilter = typeFilter; } + + public HyperionSerializerSettings WithPreserveObjectReference(bool preserveObjectReferences) + => new HyperionSerializerSettings( + preserveObjectReferences: preserveObjectReferences, + versionTolerance: VersionTolerance, + knownTypesProvider: KnownTypesProvider, + packageNameOverrides: PackageNameOverrides, + surrogates: Surrogates, + disallowUnsafeType: DisallowUnsafeType, + typeFilter: TypeFilter); + + public HyperionSerializerSettings WithVersionTolerance(bool versionTolerance) + => new HyperionSerializerSettings( + preserveObjectReferences: PreserveObjectReferences, + versionTolerance: versionTolerance, + knownTypesProvider: KnownTypesProvider, + packageNameOverrides: PackageNameOverrides, + surrogates: Surrogates, + disallowUnsafeType: DisallowUnsafeType, + typeFilter: TypeFilter); + + public HyperionSerializerSettings WithKnownTypesProvider(Type knownTypesProvider) + => new HyperionSerializerSettings( + preserveObjectReferences: PreserveObjectReferences, + versionTolerance: VersionTolerance, + knownTypesProvider: knownTypesProvider, + packageNameOverrides: PackageNameOverrides, + surrogates: Surrogates, + disallowUnsafeType: DisallowUnsafeType, + typeFilter: TypeFilter); + + public HyperionSerializerSettings WithPackageNameOverrides(IEnumerable> packageNameOverrides) + => new HyperionSerializerSettings( + preserveObjectReferences: PreserveObjectReferences, + versionTolerance: VersionTolerance, + knownTypesProvider: KnownTypesProvider, + packageNameOverrides: packageNameOverrides, + surrogates: Surrogates, + disallowUnsafeType: DisallowUnsafeType, + typeFilter: TypeFilter); + + public HyperionSerializerSettings WithSurrogates(IEnumerable surrogates) + => new HyperionSerializerSettings( + preserveObjectReferences: PreserveObjectReferences, + versionTolerance: VersionTolerance, + knownTypesProvider: KnownTypesProvider, + packageNameOverrides: PackageNameOverrides, + surrogates: surrogates, + disallowUnsafeType: DisallowUnsafeType, + typeFilter: TypeFilter); + + public HyperionSerializerSettings WithDisallowUnsafeType(bool disallowUnsafeType) + => new HyperionSerializerSettings( + preserveObjectReferences: PreserveObjectReferences, + versionTolerance: VersionTolerance, + knownTypesProvider: KnownTypesProvider, + packageNameOverrides: PackageNameOverrides, + surrogates: Surrogates, + disallowUnsafeType: disallowUnsafeType, + typeFilter: TypeFilter); + + public HyperionSerializerSettings WithTypeFilter(ITypeFilter typeFilter) + => new HyperionSerializerSettings( + preserveObjectReferences: PreserveObjectReferences, + versionTolerance: VersionTolerance, + knownTypesProvider: KnownTypesProvider, + packageNameOverrides: PackageNameOverrides, + surrogates: Surrogates, + disallowUnsafeType: DisallowUnsafeType, + typeFilter: typeFilter); } }