-
Notifications
You must be signed in to change notification settings - Fork 49
Closed
Description
As of .NET 6, a number of F# types are now handled as built-in by System.Text.Json:
- Records: serialization has always worked, and deserialization now works as one would expect, as a side-effect of the added support for non-default constructors for C# records.
list,Set: as a JSON array, like FSharp.SystemTextJson.Map: always as an object, even when the key is not string, and throws an exception if the key type is complex (eg it works withint, but throws with a record). Unlike FSharp.SystemTextJson which uses an object for string keys and an array of arrays otherwise.- option, voption: as
nullforNone/ValueNoneand the plain value forSome/ValueSome, like FSharp.SystemTextJson by default. However, there is no customizability to wrap theSomevalue instead.
I think that the only F# types that System.Text.Json still can't handle by default are unions and complex-keyed maps.
We should add an option to not handle these and let System.Text.Json take care of them instead. Maybe even an enum that lets the user choose which types they want handled by FSharp.SystemTextJson and which ones they want to leave up to System.Text.Json:
type JsonFSharpTypes =
| Records = 0x1
| Unions = 0x2
| Lists = 0x4
| Sets = 0x8
| Maps = 0x10
| Options = 0x20
| ValueOptions = 0x40
// Combinations:
| OptionalTypes = 0x60 // option and voption
| Collections = 0x1C // list, set and map
| Minimal = 0x12 // all types not already fully supported by System.Text.Json
| All = 0xffffffffMetadata
Metadata
Assignees
Labels
No labels