Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
329 stars 43 forks source link

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

Closed Tarmil closed 1 year ago

Tarmil commented 1 year 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.