Skip to content

How handle full cases from first letter #150

@kyryloboiev

Description

@kyryloboiev

С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

[]
let **should return Mailing** () =
Assert.Equal(r2d2, JsonSerializer.Deserialize( """{"Code":123,"Model":"M"}""", options))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions