fsprojects / FSharp.Data.JsonSchema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing fields are deserialized to nulls

hvester opened this issue · comments

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.

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.

Does #12 address your concern adequately?

I tested and it works as expected.

I've released this update in 2.0.0