Closed cmeeren closed 1 year ago
Good point, when the value itself is a record or union, we should be able to handle it. I know that by default System.Text.Json just returns null without calling converters when it encounters a null
during deserialization, but it looks like we can override HandleNull
in FSharp.STJ's converters to change this.
Happy that this is fixed! When will it be released?
Hi again, just wondering if it would be possible to create a new release with this change. 🙂 Otherwise I may have to work around it in other ways, which seems unnecessary since this is already implemented here, just not released yet.
Hi, sorry I'll have a release out soon 🙂
Published in v1.2.
Thanks a lot!
The document Customizing the serialization format says:
What is the reason for the first requirement (emphasis mine)?
I ask because I was recently bitten by a bug in production. I am deserializing a JSON document to the type
MyRootRecord
, but when the JSON body itself isnull
, then the returnedMyRootRecord
is also null (even though it is a record and F# does not allow null values of it), causing someNullReferenceExecption
elsewhere in the code.I would expect that if I deserialize a top-level
null
value to a record/union (not wrapped inoption
or similar), then I get a deserialization exception similar to if it had been a record field.In other words, the "throw on null" behavior should be governed by the target type, not by whether or not it's a property. (This could therefore also apply to array items, which I haven't tested.)