Serializing complex types using the built-in JSON serializer for NEventStore
I am using NEventStore in an application using CQRS / Event-Sourcing. My WireUp looks like this:
return NEventStore.Wireup.Init()
.LogToOutputWindow()
.UsingInMemoryPersistence()
.UsingSqlPersistence("TestConnection")
.WithDialect(new MsSqlDialect())
.EnlistInAmbientTransaction()
.InitializeStorageEngine()
.UsingJsonSerialization()
.Build();
Serializing events containing built-in simple data types like string and int works fine. However, when I try to serialize an event that uses the structure I have defined, the deserialized value is null.
I will probably have to mark the members of my event with attributes. But what schema does NEventStore use? There are several options in C # (attributes from DataContract Serializer, attributes from XmlSerializer, ...).
I'm also wondering what the serialization limitations are. Does NEventStore require a public empty constructor? Public setters? Or I can use readonly fields (my preference).
I was unable to figure out what the JsonStoreNonStore serializer is using. This seems to be not the same as NetwonSoft as there is a separate nuget package for it.
source to share
I had the same problem and this is what I found. NEventStore uses Newtonsoft Json.net internally. Here's a link to Newtonsoft's page on how serialization works: http://www.newtonsoft.com/json/help/html/serializationguide.htm#ISerializable
You have several options for getting the type serialized. I decided to implement the System.Runtime.Serialization.ISerializable interface because I didn't want to reference the json.net dependency on the model assembly. Your case may be different.
source to share