-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add json support for F# options, lists, sets, maps and records #55108
Add json support for F# options, lists, sets, maps and records #55108
Conversation
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsContributes to #29812. Note that the changes do not include support for discriminated unions since it requires infrastructural changes touching on polymorphism support (cf. #30083). cc @dsyme @bartelink.
|
How is this going to work with trimming? Does this need an explicit public API to opt-in? |
...Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs
Show resolved
Hide resolved
The feature requires unreferenced code to function, so it can break when used with trimming. There is precedent for this, for example the converters for System.Collections.Immutable that intentionally don't take a static dependency to the types.
Maybe, but I don't see why it shouldn't be the default. The current handling of F# types is broken one way or another. |
It is not pay-for-play. Every Json serializer construction is going to pay to the FSharp checks now. |
...es/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs
Show resolved
Hide resolved
...stem.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs
Outdated
Show resolved
Hide resolved
Of course, but that argument could be made for other rarely used supported types like IAsyncEnumerable and System.Collections.Immutable. We can measure the impact of adding F# checks to warmup time and make a call based on that, however my expectation is that users conscious of startup times will switch to source generators. |
Misc user feedback collected from social media:
|
Aren't records supported by default in net5? I've even forked fsharp.stj repo to use record (de) serialization out of the box. |
They generally happen to work, however struct record deserialization is currently broken. This change fixes that particular corner case and makes support official by adding tests for all record kinds. |
Nice. Thank you for clarification. |
@eiriktsarpalis How about single case unions, list types, option types, are they covered? |
Hi @dsyme, options and lists are supported special cases but other DUs have not been added yet. |
...es/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs
Outdated
Show resolved
Hide resolved
...es/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs
Outdated
Show resolved
Hide resolved
...es/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs
Outdated
Show resolved
Hide resolved
...Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs
Outdated
Show resolved
Hide resolved
3f96c58
to
dd78c62
Compare
FWIW I wrote a benchmark comparing cold start serialization for main and the PR branch: https://gist.github.com/eiriktsarpalis/ecb9259ee92940469d19989f81383dfd. Running statistical tests with 3% threshold seems to indicate no notable performance regressions. |
e3aef95
to
2e79342
Compare
011b5ff
to
89cf0ce
Compare
...Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; however not familiar with F# so can't comment on the value add here without the support for "discriminated unions".
Heads up: I just pushed a commit that makes discriminated unions explicitly throw |
The trimming annotations LGTM. |
d6cc6cd
to
f4bdfda
Compare
This reverts commit 2e793422dca84bd22d55cdfa2cd6c9b6c5d4963e.
f13a21d
to
17a76a0
Compare
Hello @eiriktsarpalis! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Contributes to #29812 by adding support for the following types:
Note that the changes do not include support for discriminated unions, attempting to serialize a DU will now throw
NotSupportedException
. See #29812 (comment) for an explanation why we're doing this. We can revisit this approach in future releases of .NETcc @dsyme @bartelink.