Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port UnionConverter to STJ #43

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/FsCodec.SystemTextJson/Options.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ open System.Text.Json.Serialization
type Options private () =

static let defaultConverters : JsonConverter[] =
[| JsonOptionConverter()
JsonRecordConverter() |]
[| JsonOptionConverter(); JsonRecordConverter() |]

/// Creates a default set of serializer options used by Json serialization. When used with no args, same as `JsonSerializerOptions()`
static member CreateDefault
Expand Down
2 changes: 1 addition & 1 deletion src/FsCodec.SystemTextJson/UnionConverter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module private Union =
&& not (typeHasJsonConverterAttribute propertyType)

/// Prepare arguments for the Case class ctor based on the kind of case and how F# maps that to a Type
/// and/or whether we need to let json.net step in to convert argument types
/// and/or whether we need to defer to System.Text.Json
let mapTargetCaseArgs (element : JsonElement) options (props : PropertyInfo[]) : obj [] =
match props with
| [| singleCaseArg |] when propTypeRequiresConstruction singleCaseArg.PropertyType ->
Expand Down
3 changes: 1 addition & 2 deletions tests/FsCodec.SystemTextJson.Tests/SerdesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ module StjCharacterization =
// - and is not in alignment with the FsCodec.NewtonsoftJson default options
// see https://github.com/dotnet/runtime/issues/28567#issuecomment-53581752 for lowdown
let asRequiredForExamples : System.Text.Json.Serialization.JsonConverter [] =
[| JsonOptionConverter()
JsonRecordConverter() |]
[| JsonOptionConverter(); JsonRecordConverter() |]
type OverescapedOptions() as this =
inherit TheoryData<System.Text.Json.JsonSerializerOptions>()

Expand Down
2 changes: 1 addition & 1 deletion tests/FsCodec.SystemTextJson.Tests/UnionConverterTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ let ``deserializes properly`` () =

let (|Q|) (s: string) = JsonSerializer.Serialize(s, defaultOptions)

// Renderings when NullValueHandling=Include, which is the default for Json.net, and used by the recommended Settings.CreateCorrect profile
// Renderings when NullValueHandling=Include, which is used by the recommended Settings.Create profile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options.Create

let render ignoreNulls = function
| CaseA { test = null } when ignoreNulls -> """{"case":"CaseA"}"""
| CaseA { test = Q x} -> sprintf """{"case":"CaseA","test":%s}""" x
Expand Down