Skip to content

Commit

Permalink
Fix #137: empty anonymous records
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Nov 30, 2022
1 parent df09f75 commit 8f1454b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/FSharp.SystemTextJson/Record.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type JsonRecordConverter<'T>(options: JsonSerializerOptions, fsOptions: JsonFSha
let allPublic =
recordType.GetProperties(BindingFlags.Instance ||| BindingFlags.Public)
let all =
if fields[0].GetGetMethod(true).IsPublic then
if fields.Length = 0 || fields[0].GetGetMethod(true).IsPublic then
allPublic
else
Array.append fields allPublic
Expand Down
10 changes: 10 additions & 0 deletions tests/FSharp.SystemTextJson.Tests/Test.Record.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ module NonStruct =
let actual = JsonSerializer.Serialize({| x = 1; y = "b" |}, options)
Assert.Equal("""{"x":1,"y":"b"}""", actual)

[<Fact>]
let ``deserialize empty anonymous`` () =
let actual = JsonSerializer.Deserialize("{}", options)
Assert.Equal({| |}, actual)

[<Fact>]
let ``serialize empty anonymous`` () =
let actual = JsonSerializer.Serialize({| |}, options)
Assert.Equal("{}", actual)

type PropName =
{ unnamedX: int
[<JsonPropertyName "namedY">]
Expand Down

0 comments on commit 8f1454b

Please sign in to comment.