Fleece icon indicating copy to clipboard operation
Fleece copied to clipboard

Feature request, add parameters for conditional ser/de

Open Swoorup opened this issue 5 years ago • 3 comments

Is there a way to pass parameters to OfJson or ToJson 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.

Swoorup avatar Sep 01 '20 07:09 Swoorup

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.

wallymathieu avatar Sep 01 '20 09:09 wallymathieu

Or if you can pass the revision as a type parameter?

wallymathieu avatar Sep 01 '20 10:09 wallymathieu

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

Swoorup avatar Sep 01 '20 10:09 Swoorup