core
core copied to clipboard
Add JsonDefault attribute for fields
This would allow deserializing optional JSON fields to something else than an option type. For example:
type MyRecord =
{
[<JsonDefault 42>] x: int
y: string
}
Json.Deserialize<MyRecord> """{"x": 1, "y": "hello"}"""
// Returns { x = 1; y = "hello" } as usual
Json.Deserialize<MyRecord> """{"y": "hello"}"""
// Returns { x = 42; y = "hello" } instead of failing
Or maybe this could be an optional argument to OptionalFieldAttribute rather than a new attribute.