Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithSkippableOptionFields fails roundtrip when option inside union #175

Open
sWW26 opened this issue Nov 6, 2023 · 0 comments
Open

WithSkippableOptionFields fails roundtrip when option inside union #175

sWW26 opened this issue Nov 6, 2023 · 0 comments

Comments

@sWW26
Copy link

sWW26 commented Nov 6, 2023

Noticed this issue when using ThothLike().WithSkippableOptionFields() however a minimal repro can be achieved with WithSkippableOptionFields() alone.

Repro:

open System.Text.Json
open System.Text.Json.Serialization

let opts = JsonFSharpOptions().WithSkippableOptionFields().ToJsonSerializerOptions()

type MyUnion =
    | Case1 of int option
    | Case2 of bool option
    
type MyRecord = { Field1: MyUnion }

let json = JsonSerializer.Serialize({ Field1 = Case1 None }, opts)
let value = JsonSerializer.Deserialize<MyRecord>(json, opts)

Throws exception:

Unhandled exception. System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $ | LineNumber: 0 | BytePositionInLine: 4.
 ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant