Skip to content

1.4 regression: Invalid JSON when serializing unions for some configurations #205

Closed as duplicate

Description

@cmeeren

Repro code:

open System.Text.Json.Serialization

type MyEnum =
    | A
    | B

[<Fact>]
let ``Repro`` () =
    let options = JsonSerializerOptions(WriteIndented = true)
    options.Converters.Add(JsonFSharpConverter(JsonFSharpOptions.FSharpLuLike()))
    let json = JsonSerializer.Serialize({| MyField = A |}, options)

    %json
        .Should()
        .Be(
            """{
  "MyField": "A"
}"""
        )

Expected output (and actual output with 1.3):

{
  "MyField": "A"
}

Actual output with 1.4 (invalid JSON):

  {
    "MyField": 
    "Case": "A"
  }

Activity

  1. cmeeren commented on Jun 13, 2025

    @cmeeren
    ContributorAuthor

    Another format that fails in the same way:

    JsonFSharpConverter(JsonFSharpOptions.Default().WithUnionUnwrapFieldlessTags())

    This horribly broke our production systems. But I guess that's on us for not testing thoroughly enough.

  2. changed the title [-]1.4 regression: Invalid JSON for some configurations[/-] [+]1.4 regression: Invalid JSON when serializing unions for some configurations[/+] on Jun 13, 2025
  3. Tarmil commented on Jun 13, 2025

    @Tarmil
    Owner

    Ouch, I'm pretty stunned that this managed to pass through my tests :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions