-
Notifications
You must be signed in to change notification settings - Fork 37
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
UnionContractEncoder - a way to wrap non record fields #44
Comments
I would recommend that all union case payloads use record types, in order to encourage explicit modelling and evolution of the serialization contract. In fact, earlier versions would throw if the payload used anything but a record type. This has been relaxed by having the encoder generator accept a Converting values into objects makes implicit assumptions about the encoding format (it is not given that the encoding |
This makes a lot of sense to me. Thank you for a very thorough answer, and your comments on my commit. |
Hi!
FsCodec uses
UnionContractEncoder
to serialize/deserialize the fields of cases of a DU. For example:may be serialized as
This is excellent.
However, a non-record field like the following...
will be serialized to
This is less excellent because it makes "upgrading" an event to have more fields difficult without resorting to explicit event versioning. One way to fix this is to represent the event as
which will be serialized as
You can see how it would simple to upgrade this to the code at the top of this post as it's a purely additive change w/r/t the serialized form.
TypeShape currently does not support this behavior. I see a few ways forward:
UnionContractEncoder.Create
which may take a customIMemberVisitor
. If this were available, I would be able to inject something similar to the code in this commit.IMemberVisitor
's behavior as demoed in the above commit.requireRecordPayloads
parameter to a DU with 3 cases:requireRecordPayloads
,wrapNonRecordPayloads
, andnormal
.Are there any other solutions you think may be better?
Linking the referenced FsCodec issue.
The text was updated successfully, but these errors were encountered: