Closed tuyen-vuduc closed 2 years ago
Hi, yes the library is still in development (check the 'develop' branch),
for an example of a custom json serializer check the project: https://github.com/NEventStore/NEventStore.CustomJsonSerializerSample
Thank you @AGiorgetti.
However, it doesn't really relate to my issue. My issue is to provide a custom IDocumentSerializer to UsingMongoPersistence.
What should I do?
Actually, my custom IDocumentSerializer not even reached. I create a new EventMessage, then commit following the example.
the problem lies in this code line: "serializer.Deserialize
it works only if the custom IDocumentSerializer produces array of bytes, that part need some love.
there should be a ByteStreamDocumentSerializer somewhere in NEventStore (if i remind well).
I'm honestly not sure if we really would want to keep this document serializer, I think in the original design was a way to convert one object to another, but I have to review the code to look for some hints.
Why do you need to customize the serialization ? can't you do that using the standard MongoDB mapping?
That is a not optional parameter of this method UsingMongoPersistence.
As I debugged, my custom deserializer isn't reached yet. I think that is an internal issue.
The the '.deserialize()' methos is not called because the payload of the commit is a bson document,
the whole code fragment of interest is (line 70 on the master branch, have to check on develop, but there will be something similar there too):
.Select(e => e.AsBsonDocument[MongoCommitFields.Payload].IsBsonDocument ? BsonSerializer.Deserialize<EventMessage>(e.AsBsonDocument[MongoCommitFields.Payload].ToBsonDocument()) : serializer.Deserialize<EventMessage>(e.AsBsonDocument[MongoCommitFields.Payload].AsByteArray))
if the payload is a bson document the standard MongoDB serialization will be used, any other option will be handled as a byte[]. That's why I said we will probably get rid of the DocumentSerializer sooner or later, I bet no one really used it with the Mongo Persistence
@kanvuduc have you tried the develop branch? the mongo mapping can be customized using a BsonSerializer (check line 139).
It's something I've to checkout, we may need to to work with custom json serializer for Events to avoid TypeSystem as Schema and handle gracefully versioning.
Let me know if a custom serializer helps (no time to check for the next 2 weeks).
closing due to inactivity
Hi,
I tried to use and create custom IDeserializer using JSON.NET but it keeps saying a casting exception at line 70, ExtensionMethods.cs. BsonString -> BsonBinaryData