-
Notifications
You must be signed in to change notification settings - Fork 19
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
SystemTextJson: Support automatic TypeSafeEnum/Union converter selection #69
Conversation
@Tarmil As a matter of interest, does i.e. as covered in /tests/FsCodec.SystemTextJson.Tests/AutoUnionTests.fs: |
@bartelink The "iff all cases are nullary" aspect is not possible right now in FSharp.SystemTextJson, but I would be open to adding it as an option. |
Thanks @Tarmil. For current projects, I personally am happy with FsCodec's featureset and the fact that it is a small codebase. But knowing that there's a way more complete superset of it out there, should I wish to vary the representation from a single (pair of) hard wired ones etc is definitely a big part of that happiness. I'm also not 100% decided on whether it's a misfeature in practice - it took me a long time to talk myself into risking providing a feature that can fail at run time for any DU when it crosses the divide from all nullary to/from one or more cases with bodies during the lifetime of a project, especially when there are no hints nearby to a random developer making what they perceive as a tiny change. I guess if anyone also wants it, they'll ask and/or send a PR in due course ;) |
To add this "
|
While the general advice, esp in README.md is that Explicit is Better than Implicit and having a
JsonConverter
tag per type explicitly indicating for all DU types whether to:a) use the
TypeSafeEnumConverter
to map it to astring
if possibleb) use the more general
UnionConverter
if that's not the casec) trigger
System.Text.Json
s fail fast guard if neither is presentUnionOrTypeSafeEnumConverterFactory
implements a behavior that dynamically selects from the first two.The primary risk (aside from the fact that its no longer clear per Union type in the code that it is participating in JSON encoding/decoding) is that a type that starts off using TSEC (and rendering as a JSON
string
) suddenly flips to requiring/rendering a JSONobject
. The thought of some automatic upconversion logic does not give me warm fuzzies.For more details and discussion of the tradeoffs, see the associated STJ feature RFC