Skip to content

Commit

Permalink
Always pass the type when calling untyped JsonSerializer.Serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Jan 25, 2020
1 parent d24bd67 commit 479c381
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/FSharp.SystemTextJson/Union.fs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ type JsonUnionConverter<'T>(options: JsonSerializerOptions, fsOptions: JsonFShar
fail "case field" &reader ty

let writeFieldsAsRestOfArray (writer: Utf8JsonWriter) (case: Case) (value: obj) (options: JsonSerializerOptions) =
for field in case.Dector value do
JsonSerializer.Serialize(writer, field, options)
(case.Fields, case.Dector value)
||> Array.iter2 (fun field value ->
JsonSerializer.Serialize(writer, value, field.Type, options)
)
writer.WriteEndArray()

let writeFieldsAsArray (writer: Utf8JsonWriter) (case: Case) (value: obj) (options: JsonSerializerOptions) =
Expand All @@ -301,7 +303,7 @@ type JsonUnionConverter<'T>(options: JsonSerializerOptions, fsOptions: JsonFShar
||> Array.iter2 (fun field value ->
if not (options.IgnoreNullValues && isNull value) then
writer.WritePropertyName(field.Name)
JsonSerializer.Serialize(writer, value, options)
JsonSerializer.Serialize(writer, value, field.Type, options)
)
writer.WriteEndObject()

Expand Down

0 comments on commit 479c381

Please sign in to comment.