commanded / recipes

Commanded recipes
12 stars 1 forks source link

[Recipe] Event deserialization and decoding #19

Open slashdotdash opened 3 years ago

slashdotdash commented 3 years ago

How to deserialize events to their Elixir types.

Commanded uses JSON as the event data and metadata serialization format by default. This means that type information is lost when serializing Elixir structs to JSON and requires one to implement the Commanded.Serialization.JsonDecoder to decode strings to their actual Elixir type, such as DateTime.

One possible option for automatic deserialization would be to provide a typespec for the domain event structs and use the defined types to deserialize events. The Spec library provides structure decoding from a typespec and could be used via a custom event store serializer.