Skip to content

Commit 8f1454b

Browse files
committed
Fix #137: empty anonymous records
1 parent df09f75 commit 8f1454b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/FSharp.SystemTextJson/Record.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type JsonRecordConverter<'T>(options: JsonSerializerOptions, fsOptions: JsonFSha
3333
let allPublic =
3434
recordType.GetProperties(BindingFlags.Instance ||| BindingFlags.Public)
3535
let all =
36-
if fields[0].GetGetMethod(true).IsPublic then
36+
if fields.Length = 0 || fields[0].GetGetMethod(true).IsPublic then
3737
allPublic
3838
else
3939
Array.append fields allPublic

tests/FSharp.SystemTextJson.Tests/Test.Record.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ module NonStruct =
162162
let actual = JsonSerializer.Serialize({| x = 1; y = "b" |}, options)
163163
Assert.Equal("""{"x":1,"y":"b"}""", actual)
164164

165+
[<Fact>]
166+
let ``deserialize empty anonymous`` () =
167+
let actual = JsonSerializer.Deserialize("{}", options)
168+
Assert.Equal({| |}, actual)
169+
170+
[<Fact>]
171+
let ``serialize empty anonymous`` () =
172+
let actual = JsonSerializer.Serialize({| |}, options)
173+
Assert.Equal("{}", actual)
174+
165175
type PropName =
166176
{ unnamedX: int
167177
[<JsonPropertyName "namedY">]

0 commit comments

Comments
 (0)