From 2481fb6a8812f940f98199ea5e6b93707847ec4d Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Mon, 3 Jan 2022 10:27:02 +0000 Subject: [PATCH] Fix UnionConverter --- CHANGELOG.md | 3 +++ src/FsCodec.SystemTextJson/UnionConverter.fs | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b7eabe..4cdc65f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The `Unreleased` section name is replaced by the expected version of next releas ## [Unreleased] ### Added + +- `SystemTextJson.UnionConverter`: Complete port of equivalent functionality in `NewtonsoftJson` equivalent [#59](https://github.com/jet/FsCodec/pull/59) + ### Changed - `SystemTextJson`: Target `System.Text.Json` v `6.0.1` [#59](https://github.com/jet/FsCodec/pull/59) diff --git a/src/FsCodec.SystemTextJson/UnionConverter.fs b/src/FsCodec.SystemTextJson/UnionConverter.fs index d068ad1..f693910 100755 --- a/src/FsCodec.SystemTextJson/UnionConverter.fs +++ b/src/FsCodec.SystemTextJson/UnionConverter.fs @@ -131,7 +131,8 @@ type UnionConverter<'T>() = for fieldInfo, fieldValue in Seq.zip fieldInfos fieldValues do if fieldValue <> null || options.DefaultIgnoreCondition <> Serialization.JsonIgnoreCondition.Always then writer.WritePropertyName(fieldInfo.Name) - JsonSerializer.Serialize(writer, fieldValue, options) + let element = JsonSerializer.SerializeToElement(fieldValue, fieldInfo.PropertyType, options) + element.WriteTo writer writer.WriteEndObject()