-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Version Information
Akka 1.4.31
Akka.Quartz.Actor 1.4.31`
Describe the bug
When using Akka custom message serializer and QuartzPersistentActor it fails to deserialize message from binary in QuartzPersistentJob.Execute, as it searches for serializer for typeof(object) which is Akka.Serialization.NewtonSoftJsonSerializer by default. However, initially, the message was serialized with a custom serializer in QuartzPersistentJob.CreateBuilderWithData.
I have custom serializers defined in Akka to serialize messages using protobuf. I inherit my serializers from SerializerWithStringManifest and use manifest that is based on the message type. When doing
var message = sys.Serialization.FindSerializerForType(typeof(object)).FromBinary(messageBytes, typeof(object));
in QuartzPersistentJob.Execute, it can't find proper serializer for type typeof(object) and returns Akka.Serialization.NewtonSoftJsonSerializer (default) which can't deserialize, because bytes are not json bytes, but protobuf bytes.
I tried to implement a custom serializer to handle deserializaion of typeof(object), but there is no way to figure out which exact type the bytes belong to, when the second argument type is always object type:
public class ObjectSerializer : Akka.Serialization.Serializer
{
// ....
public override object FromBinary(byte[] bytes, Type type)
{
// typeof(type) == typeof(object)
// how to figure out which class is encoded in bytes?
}
}
FromBinary is called from here:

To Reproduce
Steps to reproduce the behavior:
- Register a custom Akka binary serializer that is not JSON serializer.
- Enable
Quartzlogs. - Create
QuartzPersistentActorand schedule a job via it with a message that is serialized by serializer from1.. - When job is triggered you shoud see an error like this

Expected behavior
Pass correct Type type to FromBinary when executing a job, not typeof(object). Or introduce any other solution that will fix the issue.
Users of Akka.Quartz.Actor must be able to use any custom serializers.
Actual behavior
Serialized messages can't be deserialized back.
Environment
Windows 10, .NET 5