Tarmil / FSharp.SystemTextJson

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

Convert array to `[Flags]` enum #115

Closed xperiandri closed 2 years ago

xperiandri commented 2 years ago

Is it supported to convert an array of strings to a [Flags] enum?

"allowedCustomerOperations": [
      "Delete",
      "Update",
      "Read"
  ],

[Flags]
type AllowedCustomerOperations =
| Read = 0
| Update = 1
| Delete = 2
Tarmil commented 2 years ago

Since flag enums are a general .NET feature and not specifically F# types, I don't want to handle them in FSharp.SystemTextJson. But I think this would be a great suggestion to make in https://github.com/dotnet/runtime for inclusion in System.Text.Json itself, as optional behavior for its built-in JsonStringEnumConverter.

xperiandri commented 2 years ago

Agree, thanks https://github.com/dotnet/runtime/issues/70864