Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request, add parameters for conditional ser/de #93

Open
Swoorup opened this issue Sep 1, 2020 · 3 comments
Open

Feature request, add parameters for conditional ser/de #93

Swoorup opened this issue Sep 1, 2020 · 3 comments
Labels

Comments

@Swoorup
Copy link

Swoorup commented Sep 1, 2020

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.

@wallymathieu
Copy link
Member

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
Copy link
Member

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

@Swoorup
Copy link
Author

Swoorup commented Sep 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants