Missing fields are deserialized to nulls
hvester opened this issue · comments
Heikki Vesterinen commented
If json does not contain a field corresponding to a property then I would assume the deserialization to fail instead of leaving the value of the property as null. I'm wondering if this is intentional or a bug?
#r "nuget: FSharp.Data.JsonSchema"
open FSharp.Data
type Foo = { Bar : string }
Json.Deserialize<Foo>("{}")
// val it : Foo = { Bar = null }
Seems to be caused by IgnoreNullValues=true
in the DefaultOptions.
Ryan Riley commented
The System.Text.Json
serializer currently allows things we may not allow in the JSON Schema. This isn't strictly wrong, as if you validated the JSON against the schema, it should fail. However, we could probably improve this such that even deserialization adheres to what we want.
Ryan Riley commented
Does #12 address your concern adequately?
Heikki Vesterinen commented
I tested and it works as expected.
Ryan Riley commented
I've released this update in 2.0.0