From 3bd8c63055085e98e755b19786aa9a000388b750 Mon Sep 17 00:00:00 2001 From: Jack Wild Date: Tue, 12 May 2020 15:58:07 +0100 Subject: [PATCH] Don't use Akka deserialization when using LegacySerialization is on. (#135) Co-authored-by: Jack Wild --- .../Journal/MongoDbJournal.cs | 13 +++++++++++++ .../Snapshot/MongoDbSnapshotStore.cs | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Akka.Persistence.MongoDb/Journal/MongoDbJournal.cs b/src/Akka.Persistence.MongoDb/Journal/MongoDbJournal.cs index bb9aac6..3003fce 100644 --- a/src/Akka.Persistence.MongoDb/Journal/MongoDbJournal.cs +++ b/src/Akka.Persistence.MongoDb/Journal/MongoDbJournal.cs @@ -331,6 +331,19 @@ private JournalEntry ToJournalEntry(IPersistentRepresentation message) private Persistent ToPersistenceRepresentation(JournalEntry entry, IActorRef sender) { + if (_settings.LegacySerialization) + { + var manifest = string.IsNullOrEmpty(entry.Manifest) ? entry.Payload.GetType().TypeQualifiedName() : entry.Manifest; + + return new Persistent( + entry.Payload, + entry.SequenceNr, + entry.PersistenceId, + manifest, + entry.IsDeleted, + sender); + } + var legacy = entry.SerializerId.HasValue || !string.IsNullOrEmpty(entry.Manifest); if (!legacy) { diff --git a/src/Akka.Persistence.MongoDb/Snapshot/MongoDbSnapshotStore.cs b/src/Akka.Persistence.MongoDb/Snapshot/MongoDbSnapshotStore.cs index e4546d2..f3f3af8 100644 --- a/src/Akka.Persistence.MongoDb/Snapshot/MongoDbSnapshotStore.cs +++ b/src/Akka.Persistence.MongoDb/Snapshot/MongoDbSnapshotStore.cs @@ -165,6 +165,16 @@ private SnapshotEntry ToSnapshotEntry(SnapshotMetadata metadata, object snapshot private SelectedSnapshot ToSelectedSnapshot(SnapshotEntry entry) { + if (_settings.LegacySerialization) + { + return new SelectedSnapshot( + new SnapshotMetadata( + entry.PersistenceId, + entry.SequenceNr, + new DateTime(entry.Timestamp)), + entry.Snapshot); + } + var legacy = entry.SerializerId.HasValue || !string.IsNullOrEmpty(entry.Manifest); if (!legacy)