From 7b340d9885daaa2ff8e3eb15c26950a8da5c10a1 Mon Sep 17 00:00:00 2001 From: Bruno Cadorette Date: Tue, 31 Mar 2020 12:56:25 -0400 Subject: [PATCH] Get the type of the value instead of the field's type when serializing fields --- src/Encode.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Encode.fs b/src/Encode.fs index cfff75a..040f74e 100644 --- a/src/Encode.fs +++ b/src/Encode.fs @@ -412,10 +412,10 @@ module Encode = FSharpType.GetRecordFields(t, allowAccessToPrivateRepresentation=true) |> Array.map (fun fi -> let targetKey = Util.Casing.convert caseStrategy fi.Name - let encoder = autoEncoder extra caseStrategy skipNullField fi.PropertyType fun (source: obj) (target: JObject) -> let value = FSharpValue.GetRecordField(source, fi) if not skipNullField || (skipNullField && not (isNull value)) then // Discard null fields + let encoder = autoEncoder extra caseStrategy skipNullField (value.GetType()) target.[targetKey] <- encoder.Encode value target) boxEncoder(fun (source: obj) ->