Open Swoorup opened 4 years ago
That's an interesting question. One way to do it would perhaps be to have ofJson and toJson separated from the types in order to be able to invoke the correct format for the different revisions. Another way would perhaps be to do some conditional compilation to generate two different types for the different revisions.
Or if you can pass the revision as a type parameter?
The need mostly came from ES, you might have old events which are not updated to the latest revision. But still need to be upconvered for parsing. So possible I am thinking as a parameter to parseJson <string> (event.SchemaRevision, event.EventType)
?
type EventWrite<'payload, 'metadata> =
{ Id: Guid // ID of the event
StreamId: StreamId // Id of the stream this event belongs to
VersionNumber: VersionNumber // Sequence number of the event in a single stream
SchemaRevision: int. // Schema revision of the payload and metadata
EventType: string // Event Type
Payload: 'payload // Event data
Timestamp: DateTime } // Timestamp the event was generated
Is there a way to pass parameters to
OfJson
orToJson
properties?I would like to conditionally switch between different versions of underlying JSON model based on a parameter for example
revision
, specially for DU types, where revisions are not part of the main type being serialized/deserialized.