Tarmil / FSharp.SystemTextJson

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

Allow overriding generic types #180

Open Tarmil opened 4 months ago

Tarmil commented 4 months ago

Allow using typedefof to override options for all instances of a generic type. Example:

let options =
    FSharpJsonOptions()
        .WithOverrides(fun o -> dict [ typedefof<Result<_, _>>, o.WithUnionTagName("Result") ])
        .ToJsonSerializerOptions()

JsonSerializer.Serialize((Ok "test": Result<string, string>), o)
// --> {"Result":"Ok","Fields":["test"]}