Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
323 stars 44 forks source link

#161 Allow using single-case unions as dictionary keys #168

Closed Tarmil closed 11 months ago

Tarmil commented 11 months ago

For example:

open System.Text.Json
open System.Text.Json.Serialization

type CountryCode = CountryCode of string

let d = dict [
    CountryCode "fr", 1
    CountryCode "us", 2
]

JsonSerializer.Serialize(d, JsonFSharpOptions().ToJsonSerializerOptions())
// Returns: {"fr":1,"us":2}

Note: due to dotnet/runtime#77326, this requires System.Text.Json 8.0.