forked from akkadotnet/akka.net
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix in resolving serializer id (akkadotnet#3135)
* Fix in resolving serializer id Serializer id is now only determined once, upon initialisation. And its the serializer implementation which dictates where that id comes from. We no longer assume it always comes from the hocon config. * Forgot the nullserializer case. * Api Approval * Updated according to remarks * Added spec * Fix tests
- Loading branch information
1 parent
5033644
commit 89a1d6b
Showing
3 changed files
with
96 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Linq; | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Akka.Serialization; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Xunit; | ||
|
||
namespace Akka.Tests.Serialization | ||
{ | ||
public class CustomSerializerSpec | ||
{ | ||
/// <summary> | ||
/// Here we basically verify that a serializer decides where its Serializer Identifier is coming | ||
/// from. When using the default Serializer base class, it read from hocon config. But this should not be | ||
/// a neccesity | ||
/// </summary> | ||
[Fact] | ||
public void Custom_serializer_must_be_owner_of_its_serializerId() | ||
{ | ||
var config = ConfigurationFactory.ParseString(@" | ||
akka.actor { | ||
serializers { | ||
custom = ""Akka.Tests.Serialization.CustomSerializer, Akka.Tests"" | ||
} | ||
serialization-bindings { | ||
""System.Object"" = custom | ||
} | ||
} | ||
"); | ||
//The above config explictly does not configures the serialization-identifiers section | ||
using (var system = ActorSystem.Create(nameof(CustomSerializerSpec), config)) | ||
{ | ||
var serializer = (CustomSerializer)system.Serialization.FindSerializerForType(typeof(object)); | ||
Assert.Equal(666, serializer.Identifier); | ||
} | ||
} | ||
} | ||
|
||
public class CustomSerializer : Serializer | ||
{ | ||
public CustomSerializer(ExtendedActorSystem system) : base(system) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// This custom serializer overrides the Identifier implementation and returns a hard coded value | ||
/// </summary> | ||
public override int Identifier => 666; | ||
|
||
public override bool IncludeManifest => false; | ||
|
||
public override byte[] ToBinary(object obj) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override object FromBinary(byte[] bytes, Type type) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters