Open cmeeren opened 10 months ago
Could this be related to Option<_>
using [<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
?
Yes, it is on purpose that None and ValueNone are serialized as null. I am open to adding an option to customize this though!
Would be great! I am not serializing for idiomatic JSON, but for displaying structures of F# data (in a better way than %A
), so displaying None
instead of null
would help my users.
Note by the way that the docs for WithUnwrapOption
are misleading:
It says that if set, None
is serialized as null
. While this technically doesn't say that if it's not set, then None
is not serialized as null
, it does give a strong impression that that's the intended meaning.
Also relevant here:
Hi! Just wondering if it would be possible to implement this soon-ish (say, during the coming week or two)? I need to decide whether to work around this, but the point is moot if this could be supported upstream. 🙂
Yes, it is on purpose that None and ValueNone are serialized as null.
By the way, ValueNone
is serialized as ValueNone
, not null
(regardless of WithUnwrapOption
).
When using
WithUnwrapOption(false)
,None
still serializes tonull
.(I am serializing for logging/assertion/debugging purposes and want
None
/ValueNone
to serialize to the strings"None"
/"ValueNone"
, as I expect is the intended functionality withWithUnwrapOption(false)
.)This fails with: