Brian Low
Brian Low

Reputation: 11811

JOliver's EventStore: Cannot read events when using ServiceStack serializer

EventMessage.Body isn't deserialized back into the original object when using ServiceStack. Instead EventMessage.Body is a JSON string.

To reproduce:

  1. Open the EventStore project and navigate to the EventStore.Example project
  2. Replace the EventStore.Serialization.Json references with project references to EventStore.Serialization.ServiceStack
  3. Turn off assembly signing on EventStore.Example project
  4. Change MainProgram.WireupEventStore to .UsingServiceStackJsonSerialization()
  5. Add the following code near the end of MainProgram.Main():

-

var stream = store.OpenStream(StreamId, 0, int.MaxValue);
var myFirstEvent = (SomeDomainEvent) (stream.CommittedEvents.First().Body);
Console.Out.WriteLine("MyFirstEvent.Value=" + myFirstEvent.Value);

Upvotes: 2

Views: 353

Answers (1)

mythz
mythz

Reputation: 143409

If it's a string and you're expecting SomeDomainEvent you could use ServiceStack's FromJson Extension method, i.e:

var myFirstEvent = stream.CommittedEvents.First().Body.FromJson<SomeDomainEvent>();
Console.Out.WriteLine("MyFirstEvent.Value=" + myFirstEvent.Value);

Upvotes: 1

Related Questions