core icon indicating copy to clipboard operation
core copied to clipboard

Add JsonDefault attribute for fields

Open Tarmil opened this issue 7 years ago • 0 comments

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.

Tarmil avatar Sep 18 '18 10:09 Tarmil