FSharp.SystemTextJson
FSharp.SystemTextJson copied to clipboard
How handle full cases from first letter
Сan FSharp.SystemTextJson work with case like this when I have only 1 letter or not full word and I want to return
Example: in json I have "Mail" or "m" and I want to return Comunication.Mailing
open System
open System.Text.Json
open System.Text.Json.Serialization
[<JsonFSharpConverter(JsonUnionEncoding.FSharpLuLike)>]
type Comunication =
| [<JsonName"MAILING">] Mailing
| [<JsonName "STANDART>] Standart
type Robot = {
Code : int
Model : Comunication
}
[<EntryPoint>]
let main args =
let r2d2 = { Code = 123; Model = AddressType.Mailing }
let x = JsonSerializer.Deserialize<Robot>( """{"Code":123,"Model":"M"}"""
0
[<Fact>]
let **should return Mailing** () =
Assert.Equal(r2d2, JsonSerializer.Deserialize<Robot>( """{"Code":123,"Model":"M"}""", options))
There is no support for partial values, but you can put several names explicitly: [<JsonName("MAILING", "MAIL", "M")>].