Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
329 stars 43 forks source link

Fix #151: do not wrap null with Some #153

Closed SamuelBerger closed 1 year ago

SamuelBerger commented 1 year ago

Fixes #151

I have changed 2 existing tests because

type Person = { FirstName: string; LastName: string voption option }

{ "FirstName": "Marie" } and { "FirstName": "Marie", "LastName": null }

should both result to

{ FirstName = "Marie"; LastName = None } and not Some ValueNone (outer most Option should be None)

GBirkel commented 1 year ago

Hello! Can we get someone with write access to merge this? Looking forward to using it in our code...

SamuelBerger commented 1 year ago

Hi @Tarmil what is your opinion about the nested option problem?

Tarmil commented 1 year ago

I would rather keep the current behaviour by default, and implement this as opt-in.

An example use case I have for deserializing null differently from the absence of the field is to parse HTTP PATCH requests. This is a situation where the JSON being deserialized represents a modification of a stored object, such that:

But I also understand your use case, so a new option on JsonFSharpOptions is a welcome addition.

SamuelBerger commented 1 year ago

Yes, that makes sense. I will (hopefully this week) change the PR so it does not change the current behaviour and just fixes the bug.

The opt-in for flattening nested options would be a different change.

I also understand now the WithSkippableOptionFields configuration. It is a 1:1 replacement for https://github.com/Tarmil/FSharp.SystemTextJson/blob/master/docs/Format.md#skippable I initially understood it as "I won't be so harsh and throw an exception if you skip a field of type option instead of giving me a null" (as it was before 1.0 release)

SamuelBerger commented 1 year ago

@Tarmil one last thing to be on the safe side. Do you confirm #151 is a bug?

SamuelBerger commented 1 year ago

I assume it is not a bug then :) and close this tiny PR.